image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.91k stars 611 forks source link

Error: PNG image and JPEG failed loading #2330

Open itsNiccoloSabatini opened 4 weeks ago

itsNiccoloSabatini commented 4 weeks ago

This happens in Rust egui/eframe framework,

I add an image to my UI, written in Rust using egui and eframe, and it used to be load with the 24.9. But when I updated to 25.2 the images won't load anymore. there's a pop up saying "failed loading bytes::/imagePath: the image format Png is not supported" or the same but Jpeg.

ui.add(egui::Button::image(LocalImage::Menu.as_image()).fill(UiColor::Orange) this is how I load an image now, and LocalImage is looks something like this:

impl LocalImage {
    pub fn as_image(&self) -> egui::Image<'static> {
        match self {
            LocalImage::Green => egui::Image::new(egui::include_image!("images/colors/green.png")),
            LocalImage::Red => egui::Image::new(egui::include_image!("images/colors/red.png")),
            LocalImage::Orange => {
                egui::Image::new(egui::include_image!("images/colors/orange.png"))
            }
            LocalImage::FourG => egui::Image::new(egui::include_image!("images/icons/4g.png")),
            LocalImage::Calling => {
                egui::Image::new(egui::include_image!("images/icons/calling.png"))
            }
            LocalImage::Done => egui::Image::new(egui::include_image!("images/icons/done.png")),
            LocalImage::Error => egui::Image::new(egui::include_image!("images/icons/err.png")),
            LocalImage::Menu => egui::Image::new(egui::include_image!("images/icons/menu.png")),
            LocalImage::Time => egui::Image::new(egui::include_image!("images/icons/time.png")),
            LocalImage::TurnOff => {
                egui::Image::new(egui::include_image!("images/icons/turn-off.png"))
            }
        }
    }
}

this is an image of what happens. immagine

fastfailure commented 4 days ago

It seems the problem disappeared with latest egui/eframe version (0.29.1)

fintelia commented 3 days ago

This crate uses Cargo features to enable/disable format support. So probably what happened is that egui/eframe set default-features = false and in the process disabled support for PNG, JPEG and all the other formats.