From DynamicImage to Vec<u8> #2131
Unanswered
nricciardi
asked this question in
Q&A
Replies: 1 comment 8 replies
-
You are probably looking for the let mut bytes: Vec<u8> = Vec::new();
img2.write_to(&mut Cursor::new(&mut bytes), image::ImageOutputFormat::Png)?; If you call |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would use this image library to perform some elaboration over images. In particular, I would open an image, compress and save as base64. I would save it as base64 to include that in html page.
At the moment, I'm reading image using
File
:and then I use
base64
library.Now, I would use
image::load_from_memory
orimage::open
to obtain DynamicImage and then get the Vec from it.I have tried with
as_flat_samples_u8().unwrap().samples
andinto_bytes()
, but the Vec ofimage.read_to_end(&mut buffer)
is different from the Vec ofinto_bytes()
. This last is longer.How can I fix?
Beta Was this translation helpful? Give feedback.
All reactions