[英]Convert RgbImage into Vec<[u8; 3]>
I have an RgbImage
but for the gaussian blur algorithm I need to convert it to Vec<[u8; 3]>
我有一个
RgbImage
但对于高斯模糊算法,我需要将其转换为Vec<[u8; 3]>
Vec<[u8; 3]>
. 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
.但是在我的新项目中,由于某种原因,我收到错误
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.我不确定为什么会发生这种情况,但我认为无论如何都有更好的方法。
You need to add the crate itertools
for tuples()
.您需要为
tuples()
添加 crate itertools
。
Or you can use std's chunks_exact()
:或者你可以使用 std 的
chunks_exact()
:
for color in img.chunks_exact(3) {
new.push(color.try_into().unwrap());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.