Rust version of LodePNG
This is a pure Rust PNG image decoder and encoder. Allows easy reading and writing of PNG files without any system dependencies.
The easiest way to use LodePNG is to include the lodepng crate.
To do so, add this to your Cargo.toml
:
[]
= "2.0.0"
See API reference for details. Requires Rust 1.21 or later.
Loading image example
let image = decode32_file?;
returns image of type lodepng::Bitmap<lodepng::RGBA<u8>>
with fields .width
, .height
, and .buffer
(the buffer is a Vec
).
The RGB/RGBA pixel types are from the RGB crate, which you can import separately to use the same pixel struct throughout the program, without casting. But if you want to read the image buffer as bunch of raw bytes, ignoring the RGB(A) pixel structure, use:
= "0.8"
rgb
extern crate rgb;
use *;
…
let bytes: & = image.buffer.as_bytes;
Saving image example
encode32_file
The buffer can be a slice of any type as long as it has 4 bytes per element (e.g. struct RGBA
or (u8,u8,u8,u8)
).
Advanced
let mut state = new;
state.remember_unknown_chunks;
match state.decode
for chunk in state.info_png.unknown_chunks
// Color profile (to be used with e.g. LCMS2)
let icc_data = state.info_png.get_icc;
Upgrading from 1.x
CVec
has been replaced with a regularVec
. Delete extra.as_ref()
that the compiler may complain about.LCT_*
constants have been changed toColorType::*
.Chunk
/Chunks
renamed toChunkRef
/ChunksIter
auto_convert
is a booleanbitdepth
has a getter/setter- There is no C any more!