I got a subimage from an image in Rust. Though the document seems to list no way to save a subimage conveniently. Do I have to read each pixel to write to a buffer?
Here follows my code in Playground.
fn main() {
f();
}
fn f(){
let (w,h)=(100,100);
for (x,y) in &[(100 as u32,200 as u32)]{
let mut img = image::open("mySvg.png").unwrap();
let subimg = imageops::crop(&mut img, *x , *y , w , h );
let mut output = std::fs::File::create(format!("mySvg.{}.{}.png",x,y).as_str()).unwrap();
subimg.write_to(&mut output, ImageFormat::Png).unwrap(); //Error!!
}}
no method named `write_to` found for struct `SubImage<&mut DynamicImage>` in the current scope
--> src/main.rs:12:17
|
12 | subimg.write_to(&mut output, ImageFormat::Png).unwrap(); //Error!!
| ^^^^^^^^ method not found in `SubImage<&mut DynamicImage>`
