I am trying to add an image to my window from a pixel buffer in memory. (right now I am using cpu memory because I'm on a macbook anyway).
I don't want the image to be cached because this will be the single frame of a video (but I'm trying to make it work with a single image first, for the same reason I'll start with an hardcoded pixel buffer to begin with).
I will cut the eframe/egui bolierplate ang go to the main part inside the update fn:
egui_extras::install_image_loaders(ctx);
...
ui.heading("Video player");
let pixels = vec![0; 10_000]; // 100x100 8-bit rgb image (all black)
let img = egui::Image::from_bytes("bytes://foo", pixels);
ui.add(img);
I have added egui_extras of course. Now when I run the app I can see the window with the heading but instead of the black rectangle this warning is shown:
Some of my questions regarding the API remain unanswered also due to the lack of documentation and examples:
You can use a ColorImage
and then supply this to a Texture
. An example can be found in this noise-functions-demo source, which has this form (edited down to the essence):
let pixels: Vec<egui::Color32> = ...;
// loop to fill out pixels {
// let color: egui::Color32 = ...;
// pixels[i] = color;
texture.set(
egui::ColorImage {
size: ...,
pixels: pixels,
},
egui::TextureOptions::NEAREST,
);
let size = texture.size_vec2();
let sized_texture = egui::load::SizedTexture::new(texture, size);
ui.add(egui::Image::new(sized_texture).fit_to_exact_size(size));