Logicalshift / flo_draw

2D rendering libraries for Rust and FlowBetween
Apache License 2.0
101 stars 6 forks source link

Render to a .png file? #2

Closed mxgrey closed 2 years ago

mxgrey commented 2 years ago

Hi, thanks for developing this crate, it has a very nice API :ok_hand:

I'd really like to use this API to programmatically draw images to save to directly to PNG files. Is there a straightforward way to accomplish that? Nothing that I can see in the public API is jumping out at me.

Logicalshift commented 2 years ago

Hi, glad you like the library :-)

The examples for off-screen rendering are part of the flo_render_canvas library (flo_draw itself provides a windowed UI). You can see them here: https://github.com/Logicalshift/flo_draw/tree/v0.4/render_canvas/examples

The important functions are initialize_offscreen_rendering() for creating a render context for the current operating system and render_canvas_offscreen() for generating a raw RGBA byte array from a set of rendering instructions: this is what can be saved to a PNG or other image file format by an appropriate library. The png_triangle example shows one of the simplest ways to achieve this.

mxgrey commented 2 years ago

Ah excellent, thanks! I guess I didn't dig hard enough to find the example :grin: