Do I have to save the file? Is it possible to directly pass through ImageBuffer to png? I hope to get one vec[u8] #1799
-
let mut _rgba_image = image::RgbaImage::new(
(res.dest_right-res.dest_left).into(),
(res.dest_bottom-res.dest_top).into(),
);
_rgba_image.pixels_mut().enumerate().for_each(|pixel| {
*pixel.1 = Rgba([
data[pixel.0 * 4 + 0],
data[pixel.0 * 4 + 1],
data[pixel.0 * 4 + 2],
255,
])
});
_rgba_image.save("pngs/1.png").unwrap(); i need png encod from _rgba_image to a Vec[u8]!! |
Beta Was this translation helpful? Give feedback.
Answered by
HeroicKatora
Sep 29, 2022
Replies: 1 comment
-
You can use use std::io::Cursor;
let output = Cursor::new(vec![]);
rgba_image.write_to(&mut output, ImageOutputFormat::Png)?;
output.into_inner() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
RyanCode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
ImageBuffer::write_to
to provide an explicitWrite
target. Note that it must be seekable (some formats require seeking back), so you'll want to wrap it in aCursor
temporarily.