[egui] include_image don't work

For some reason, this macros don't work. The code complied so it sees the image (that means I wrote a correct path). But I get this:

I tried two ways to show the image

1 ->

ui.add(ImageButton::new(include_image!("../../resources/images/logo.png")));

2 (I was hoping size limitation will work) ->

ui.add_sized([window_size.x * 0.1, header_height],ImageButton::new(include_image!("../../resources/images/logo.png")));

include_image!() doesn't actually load the image, it simply includes the bytes in your program and gives you an egui::ImageSource that points to the included bytes. you still need an image loader that can resolve the ImageSource and decode the image format into rgb data.

you can implement your own image loader that decodes the png data, see egui::Context::add_image_loader(); but the easiest way to load images is to use the egui-extras crate, and call egui_extras::install_image_loaders() during app initialization. it has image loaders for common formats like png:

# add `egui-extras` crate as dependency, enable the `image` feature
$ cargo add egui-extras -F image
// install the image loader when initializing your application
// e.g. if you use `eframe`, you can do it in the `AppCreator`:
eframe::run_native(
	app_name,
	native_options,
	Box::new(|cc| {
		egui_extras::install_image_loaders(&cc.egui_ctx);
		Ok(Box::new(MyApp))
	}),
)

You're my savior