Closed RazrFalcon closed 6 years ago
The shortest method:
let image2 = image1.new_buf(image1.buf.iter().map(|px| px.a).collect());
or
let image2 = Img::new(image1.pixels().map(|px| px.a).collect(), image1.width(), image1.height());
Instead of buf = iter.collect()
, it might be slightly faster to do:
let buf2 = Vec::with_capacity(width * height);
buf2.extend(iter);
I see. Thanks.
Let's say I need to extract an alpha channel from an image. I've ended up with code like this:
It this the only way or am I missing something?