here's the main.rs
in dir PNG
use std::*;
fn main() {
const W: usize = 300;
const H: usize = 600;
let mut img: [ [u8; 4]; W*H] = [[0_u8; 4]; W*H];
for h in 0..H {
for w in 0..W {
if h/200 ==0 { img[h*W +w ] = [255_u8, 0_u8, 0_u8,255_u8] ; }
else if h/200 ==1 { img[h*W +w ] = [ 0_u8,255_u8, 0_u8,255_u8] ; }
else if h/200 ==2 { img[h*W +w ] = [ 0_u8, 0_u8,255_u8,255_u8] ; }
} }
//Saving image example
// The buffer can be a slice of any type as long as it has 4 bytes per element (e.g. struct RGBA or [u8; 4]).
lodepng::encode32_file("out.png", &img, W, H) ;
println!("out.png !");
// Loading an image example (more examples in the examples/ dir)
match lodepng::decode32_file("out.png") {
Ok(image) => println!("image.W= {} image.H= {} ..image.buffer[0]= {}", image.width, image.height, image.buffer[0] ),
Err(reason) => println!("Could not load, because: {}", reason),
}
}