簡體   English   中英

將 RgbImage 轉換為 Vec<[u8; 3]>

[英]Convert RgbImage into Vec<[u8; 3]>

我有一個RgbImage但對於高斯模糊算法,我需要將其轉換為Vec<[u8; 3]> Vec<[u8; 3]> 我在使用之前設法做到了這一點:

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]);
}

但是在我的新項目中,由於某種原因,我收到錯誤no method named tuples found for struct std::vec::IntoIter in the current scope 我不確定為什么會發生這種情況,但我認為無論如何都有更好的方法。

您需要為tuples()添加 crate itertools

或者你可以使用 std 的chunks_exact()

for color in img.chunks_exact(3) {
    new.push(color.try_into().unwrap());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM