How to avoid image caching

Hello,

I’m having an issue where, when an image file changes (by an event that executes image modifying operations), the view() function gets called but the displayed image does not change, it only changes if the path which it uses to create the image handle changes, so I assume there is some sort of caching of file paths with the file handle. Is there any way around that? I tested with a print statement, and after modifying the image with a message to do so, view() does get called to update the layout, but it only updates the image when I change the path for it, using a hack with %2 to alternate the image path works, but is far from ideal.

Ah, I just figured out a way around it, just read into bytes beforehand and the caching does not take place:

    let bytes = std::fs::read(path_file_icon)?;
    let image_handle = iced::widget::image::Handle::from_bytes(bytes);
    let image_viewer = iced::widget::image::viewer(image_handle);

This causes caching:

    let image_handle = iced::widget::image::Handle::from_path(&path_file_icon);
    let image_viewer = iced::widget::image::viewer(image_handle);
1 Like