How to dynamically rerender a image #4253
-
I'm trying to load an image, and I did it successfully via this: I'm using the following in cargo.toml:
This works great, but if, for example, I delete the image while the program is running and replace it with a new one, it does not dynamically re-render with the new image. Is there a way to force it to re-render the image? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You have to call Context::forget_image when you want the image to be reloaded. Note that doing that on every frame might increase the CPU usage significantly, so you might want to add some check that the file has changed, such as checking the modified timestamp. The default egui texture loader does not do this automatically, but if you want you can also create your own loaders with this functionality so you don't have to do it everywhere in the code. I talked about that in #3501 (comment). |
Beta Was this translation helpful? Give feedback.
You have to call Context::forget_image when you want the image to be reloaded. Note that doing that on every frame might increase the CPU usage significantly, so you might want to add some check that the file has changed, such as checking the modified timestamp. The default egui texture loader does not do this automatically, but if you want you can also create your own loaders with this functionality so you don't have to do it everywhere in the code. I talked about that in #3501 (comment).