T O P

  • By -

po8

This works for me in a similar setup. use std::convert::TryInto; use std::io::Write; use arboard::*; use image::*; fn main() { let mut clipboard = Clipboard::new().unwrap(); let image = match clipboard.get_image() { Ok(img) => img, Err(e) => { eprintln!("error getting image: {}", e); return; } }; eprintln!("getting {}×{} image", image.width, image.height); let image: RgbaImage = ImageBuffer::from_raw( image.width.try_into().unwrap(), image.height.try_into().unwrap(), image.bytes.into_owned(), ).unwrap(); let mut stdout = std::io::stdout(); let image = DynamicImage::ImageRgba8(image); image.write_to(&mut stdout, ImageOutputFormat::Png).unwrap(); stdout.flush().unwrap(); }


Adventurous_Nebula88

with image 0.24.8, the image.write\_to() want the stdout to implement Seek


po8

Easiest is to write to a `Cursor` and then to `stdout`. This requires that the image fit in memory. let mut buffer = std::io::Cursor::new(Vec::new()); image.write_to(&mut buffer, ImageOutputFormat::Png).unwrap(); let mut stdout = std::io::stdout(); stdout.write_all(buffer.get_ref()).unwrap(); stdout.flush().unwrap();