rustfltk

Display ImageBuffer on application window with Rust


what is Rust's best way to display and dynamically generated image?

I have

let image : ImageBuffer<Rgb<u8>, Vec<u8>> = ...

How do I show it in a GUI?

I tried with fltk, but didn't find anything usable for ImageBuffer.

use fltk::...

let app = App::default().with_scheme(AppScheme::Gleam);
let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
wind.set_image(Some(image));

won't work because:

the trait `ImageExt` is not implemented for image::buffer_::ImageBuffer<image::color::Rgb<u8>, Vec<u8>>`

Do I have to encode my ImageBuffer image to some specific format, so that the GUI library can decode it back and display it afterward?

Or maybe I should use some other UI library then fltk?


Solution

  • I was able to solve it with the help from mo_al_'s answear. I just had to use into_raw(), because to_rgb8() or into_rgb8() were not implemented for type.

    let w = image.width() as i32;
    let h = image.height() as i32;
    let image_rgb = RgbImage::new(&domain_image.into_raw(), w, h, ColorDepth::Rgb8).unwrap();
    ...
    let mut frame = Frame::new(0, 0, w, h, "");
    frame.set_image(Some(image_rgb));