Hello,
I am trying to iterate over pixels, using the image crate.
I thought, if something returns an iterator, you can call collect to take the collection, and store it in a Vector. But, I am getting stuck with this error, about usize
.
Code:
fn main() -> Result<(), Box<dyn Error>> {
let gray_img = open("model-y.jpeg")?.to_luma();
let image_pixels: Vec<_> = gray_img.pixels().collect();
for i in image_pixels {
println!("Pixel: {:?}", image_pixels[i]);
}
Ok(())
}
Error:
error[E0277]: the type `[&image::color::Luma<u8>]` cannot be indexed by `&image::color::Luma<u8>`
--> src/main.rs:42:33
|
42 | println!("Pixel: {:?}", image_pixels[i]);
| ^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[&image::color::Luma<u8>]>` is not implemented for `&image::color::Luma<u8>`
= note: required because of the requirements on the impl of `std::ops::Index<&image::color::Luma<u8>>` for `std::vec::Vec<&image::color::Luma<u8>>`
I am not sure how to interpret the error, or how to proceed. Any help would be very appreciated.