Crate png_codec

Source
Expand description

A library for encoding PNG images, supporting indexed images.

§Getting Started

Add the following to your Cargo.toml.

[dependencies.png_codec]
version = "0.1"

§Example

let mut data = vec![0u8; 512 * 512];
for i in 0..512 * 512 {
    data[i] = (i % 7) as u8;
}
let png = png_codec::IndexedImage {
    height: 512,
    width: 512,
    pixels: &data,
    palette: &[
        Rgba::new(0, 0, 0, 255),
        Rgba::new(255, 0, 255, 255),
        Rgba::new(255, 0, 0, 255),
        Rgba::new(0, 10, 90, 255),
        Rgba::new(255, 0, 0, 200),
        Rgba::new(255, 1, 90, 255),
        Rgba::new(0, 10, 90, 255),
    ],
};
let encoded = png.encode_png(5).unwrap();
std::fs::write("graphic.png", &encoded).expect("Failed to save image");

Structs§

Encoder
PNG file encoder
IndexedImage
Raw Data for Indexed Image
Rgb
Rgba