MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Preload large PNGs to reduce UI stutter?

01 Sep 2021, 12:29

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!
 
User avatar
jsantos
Site Admin
Posts: 3424
Joined: 20 Jan 2012, 17:18
Contact:

Re: Preload large PNGs to reduce UI stutter?

01 Sep 2021, 12:47

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.
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Preload large PNGs to reduce UI stutter?

01 Sep 2021, 13:56

Ah! Good point, I will give that a try. Thanks :-)
 
MarkSim
Topic Author
Posts: 30
Joined: 20 Apr 2021, 18:59

Re: Preload large PNGs to reduce UI stutter?

02 Sep 2021, 19:17

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?
 
User avatar
jsantos
Site Admin
Posts: 3424
Joined: 20 Jan 2012, 17:18
Contact:

Re: Preload large PNGs to reduce UI stutter?

03 Sep 2021, 13:06

It is not thread-safe. You need to invoke it from the main thread.

Who is online

Users browsing this forum: No registered users and 2 guests