Preload large PNGs to reduce UI stutter?
When I open a view containing large PNGs, the UI pauses (the animations stutter) while they are loaded and processed. These particular PNGs are not specified in the XAML; the ImageSource can change so it is a bound value.
I've managed to reduce the problem to it only happening the first time I use any particular PNGs by caching the Ptr<BitmapImage> used by filename. So for a particular PNG, like "test1.png", the same Ptr<BitmapImage> will be returned. I'm guessing Noesis recognises this and uses its internal cache to get the PNG data previously loaded..
There is a point in the code where I could preload these images without any ill effect. Is there any way I can get Noesis to preload and preprocess the BitmapImage in code without having to do some horrible hack like rending all the files invisibly in a parent view?
I currently do bitmapImage->Init() when I cache it, which I can see calls the TextureProvider to get info like width and height ... if only there was a similar call to load and process the whole thing... Or to shell that processes out to a thread..?
Thanks!
I've managed to reduce the problem to it only happening the first time I use any particular PNGs by caching the Ptr<BitmapImage> used by filename. So for a particular PNG, like "test1.png", the same Ptr<BitmapImage> will be returned. I'm guessing Noesis recognises this and uses its internal cache to get the PNG data previously loaded..
There is a point in the code where I could preload these images without any ill effect. Is there any way I can get Noesis to preload and preprocess the BitmapImage in code without having to do some horrible hack like rending all the files invisibly in a parent view?
I currently do bitmapImage->Init() when I cache it, which I can see calls the TextureProvider to get info like width and height ... if only there was a similar call to load and process the whole thing... Or to shell that processes out to a thread..?
Thanks!
Re: Preload large PNGs to reduce UI stutter?
Are you implementing your own TextureProvider? Because that way you can preload whatever you may need. You can also load the texture in a different thread and once it it ready you can use the Reload mechanism available in that API.
Re: Preload large PNGs to reduce UI stutter?
Ah! Good point, I will give that a try. Thanks :-)
Re: Preload large PNGs to reduce UI stutter?
Is RaiseTextureChanged() thread safe? I mean - can I call it from my Worker Thread once it has finished loading? Or is it better to somehow signal the main thread to call it?
Re: Preload large PNGs to reduce UI stutter?
It is not thread-safe. You need to invoke it from the main thread.