Skip to content

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

Answered by HeroicKatora
RyanCode asked this question in Q&A
Discussion options

You must be logged in to vote

You can use ImageBuffer::write_to to provide an explicit Write target. Note that it must be seekable (some formats require seeking back), so you'll want to wrap it in a Cursor temporarily.

use std::io::Cursor;

let output = Cursor::new(vec![]);
rgba_image.write_to(&mut output, ImageOutputFormat::Png)?;
output.into_inner()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RyanCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1798 on September 29, 2022 10:59.