Overview
PngBackend renders a Scene to PNG bytes. This backend requires the png feature flag and uses resvg to rasterize SVG scenes.
Usage
Constructor
new
Creates a new PNG backend with default scale factor (2.0).
PngBackend with scale = 2.0
default
Alias for new().
Methods
with_scale
Sets the pixel density multiplier.
Pixel density multiplier:
1.0= same logical pixel dimensions as SVG2.0= retina/HiDPI quality (default)- Higher values produce larger, higher-resolution images
Self for method chaining
Example:
render_scene
Renders a Scene to PNG bytes.
The scene to render
Result<Vec<u8>, String>
Ok(bytes)- PNG file data ready to writeErr(msg)- Error message if rendering failed
Implementation
The PNG backend:- Renders the scene to SVG using
SvgBackend - Loads system fonts into a
resvgfont database - Parses the SVG with
usvg - Rasterizes to a pixmap at the specified scale
- Encodes as PNG
Convenience Function
For one-shot rendering, use:Source
src/backend/png.rs