I have an RgbImage
but for the gaussian blur algorithm I need to convert it to Vec<[u8; 3]>
. I managed to do this before using:
let img: Vec<u8> = img.into_raw();
let mut new: Vec<[u8; 3]> = vec![];
for (r, g, b) in img.into_iter().tuples() {
new.push([r, g, b]);
}
But in my new project for some reason I get the error no method named tuples found for struct std::vec::IntoIter in the current scope
. I'm not sure why this is happening but I think there is a much better way to do it anyway.
CodePudding user response:
You need to add the crate itertools
for tuples()
.
Or you can use std's chunks_exact()
:
for color in img.chunks_exact(3) {
new.push(color.try_into().unwrap());
}