esskar
esskar

Reputation: 10970

Doing performant image updates

I have a messenger app on Wp8 (MVVM Light). People can create group conversations and assign images to that conversations. Those images are shown besides the conversation titles in the conversation overview, the conversation itself and also in the conversation details.

Those images are cached. It is a two layer cache using weak memory cache and also isolated memory cache. Members of the conversation group are allowed to change the images. They do that by uploading a new image to the server and sending a conversation-image-changed-message to the other group message.

Now I am looking for a performant and ellegant way to change all the images. I can receive those update-message and I can easily clear the cache, so if the image gets rebind, it loads the new image, but the problem is with the already bound-images in the view that are in my navigation back stack. When i navigate back, i do not want to reset all images in that view, but just the ones that are out-dated.

I currently, i bind the images dirctly, using a ImageSource that i retrieve from the cache. I am thinking about a kind of imagecontainer, that holds the imagesource, and having a globally imagecontainer-manager that keeps weak references of the container and provides a bindable property to the image source. everytime i receive an image update i check the container if it still holds an weak reference to that image and just raise a property change event on the image source property.

are there any other or better ideas or maybe libraries that already implemented something like that?

Upvotes: 0

Views: 81

Answers (2)

Daniel Luberda
Daniel Luberda

Reputation: 7454

I have some experience with such operations when doing Windows (WinRT, UWP) implementation for FFImageLoading library (https://github.com/molinch/FFImageLoading). You could also try it - it has transformations support (custom too).

Basically you don't want to use anything like WriteableBitmap because it forces you to use UI thread when doing some pixel/data updates. You want to use byte[] or int[] pixel data. After all pixel data manipulation you just simply convert it to WriteableBitmap.

Great helpers how to achieve that is here: https://github.com/teichgraf/WriteableBitmapEx/ (BitmapContext class)

You can call WriteableBitmap.Invalidate() to notify that it's data changed. You could also use the same WriteableBitmap image for multiple views. It'll speed up things (it's exactly how FFImageLoading does it).

Upvotes: 1

Abhilash
Abhilash

Reputation: 367

You can try out JetImageLoader by Artem. there is a blog post about this as well

Upvotes: 0

Related Questions