Skip to main content

write_png

Function write_png 

Source
pub fn write_png<P: Pixel, W: Write>(
    bitmap: &Bitmap<P>,
    out: W,
) -> Result<(), EncodeError>
Expand description

Write bitmap to out as a PNG image.

The sink out is consumed; wrap in std::io::BufWriter if buffering is needed.

Supported pixel modes:

ModePNG colour type
Rgb8RGB (24-bit)
Gray8 / Mono8Grayscale (8-bit)
Rgba8RGBA (32-bit)

§Alpha plane

For Rgb8 bitmaps: if the bitmap has an alpha plane, each RGB row is interleaved with the corresponding alpha bytes and written as RGBA PNG.

For Rgba8 bitmaps: the alpha stored within each pixel is used; any separate alpha plane is ignored.

§Errors

Returns EncodeError::UnsupportedMode for CMYK, BGR, XBGR, DeviceN, or Mono1 bitmaps. Returns EncodeError::Io or EncodeError::PngEncoder on failure.