For the moment, this crate is in construction.
If you need something, you can tell me:
If you encounter some issues, tell me.
Rust
use devpng::prelude::PNG;
fn main() -> Result<(), String> {
// Load.
let mut buf = std::fs::read("img.png")
.expect("Couldn't read the file.");
let mut png = PNG::load(&mut buf)?;
// Access Image.
let img = png.image();
// Modify image.
for x in img.iter_mut() {
*x = !*x;
}
// Store.
png.store("img.png")?;
Ok(())
}
Rust
use devpng::prelude::{ColourType, Image, PNG};
fn main() -> Result<(), String> {
let mut data = [255, 0, 0, 0, 0, 0];
let img = Image::new(&mut data[..])
.set_ncol(6)
.set_nrow(1)
.set_depth(8)
.set_colour(ColourType::RGB);
let mut buf = Vec::new();
let mut png = PNG::from_image(&mut buf, &img);
// Store.
png.store("img.png")?;
Ok(())
}
```Rust use devpng::prelude::DataStreamMut; fn main() -> Result<(), String> { // Load. let mut buf = std::fs::read("img.png") .expect("Couldn't read the file."); let mut datastream = DataStreamMut::from(&mut buf)?; // Access Image. let mut cache = datastream.idat()?; let img = cache.image();
// Modify image.
for x in img.iter_mut() {
*x = !*x;
}
// Store.
let png = datastream.rebuild(&mut Some(&mut cache));
std::fs::write("img.png", png)
.expect("Couldn't write the file.");
Ok(())
} ```
Add following lines to your Cargo.toml
:
toml
[dependencies]
devpng = "0"