0

I have a web service that returns an azure URL, I am setting that as data source for my image control in list item template.This list may contain large number of items(Now it has around 30 items only).My app memory consumption goes beyond 100 MB for this single page, some 10 MB data gets downloaded.

When user goes to some other page and comes back to this page with images from azure,My web service will be called again, and so all images would be downloaded again.Is there any way to check if images are already downloaded and prevent download again?

I am not sure about what happens under the hood while giving an URL to an image control.

This is my XAML

<Image 
   Stretch="UniformToFill" 
   Grid.Column="1" 
   Grid.Row="0" 
   VerticalAlignment="Top" 
   Source="{Binding image_name}" 
   Height="72" 
   Width="128" >
</Image>
ramiramilu
  • 17,044
  • 6
  • 49
  • 66
Prasanna Aarthi
  • 3,439
  • 4
  • 26
  • 48

3 Answers3

2

BitmapImage can check the cache for an existed copy. Of course, if you didn't set the option to ignore cache. Check this documentation page. Additionally, it can be the problem with headers in your azure storage, be sure that caching is allowed and object life time is enough.

crea7or
  • 4,421
  • 2
  • 26
  • 37
  • I am not using a bitmapimage here..I ve updated my code.. Should I create a bitmapimage from that URL and then assign it to my image control? – Prasanna Aarthi Jan 10 '14 at 09:02
  • Check [this solution](http://stackoverflow.com/questions/17261114/image-source-and-caching). If it does not help, you should check your http headers for the caching parameters. – crea7or Jan 10 '14 at 09:11
  • @PrasannaAarthi yes you can create a bitmapimage from url and do you have all images name, which want you download from url. – Jaihind Jan 10 '14 at 09:23
2

This is how I will solve the problem. Create an XML catalog of all images. In the XML have a unique thumbprint identifier, which should be generated from Image. On the first time of loading images, you will first get this XML from server and save it in isolated storage of Windows Phone. And then when user goes from item to item, download that particular image from server and save it in Isolated Storage of Windows Phone.

Now interesting questions comes with, what if new images were added on the server or existing images got renewed? In that case catalog on server also needs to be changed (updated with new information. So that next time when WP app starts, it will get the new catalog and will check for all thumbprints, it thumbprint were not found or found changed, WP app will only download those images on demand (I mean when user navigate to that item only).

So main concept is to make this XML catalog as a version profile for all images. Also note that keep this XML file simple and minimum in size. HTH.

ramiramilu
  • 17,044
  • 6
  • 49
  • 66
1

First of all - you should not download all full-size iamges from the server – 10 MB is way to much for a mobile application. You should go with some thumbnails and then when the user requests you download the full version.

If you are ok with caching as temporary solution, it is probably the easiest way to go. If you want to store the image in the phone for a longer time (that you can also control), you will have to implement your own logic here. The simplest way would probably be to maintain a dictionary of all images already downloaded and create a ValueConverter that would check the boud URL and return local one if the image exists or initiate a background download, that will raise PropertyChanged event for the bound property to show the image when it is done.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91