INNER CODE UNIT · Rust
get_bytes
silvia-odwyer/photon · crate/src/lib.rs:204
pub fn get_bytes(&self) -> Vec<u8> {
// Encode straight from raw_pixels; a DynamicImage round-trip would
// clone the frame twice.
let mut buffer = vec![];
PngEncoder::new(Cursor::new(&mut buffer))
.write_image(
&self.raw_pixels,
self.width,
self.height,
image::ColorType::Rgba8,
)
.unwrap();
buffer
}
/// Convert the PhotonImage to raw bytes. Returns a JPEG.
pub fn get_bytes_jpeg(&self, quality: u8) -> Vec<u8> {
let mut buffer = vec![];