Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Source and Caching

I use the following code to show images from a webserver:

   <Image Source="{Binding Url}" />

The image gets automatically downloaded, and I assume there is also some caching based on the Url.

My problem is, that when the app is offline, the assumably cached images are not shown.

Is there any way to change the caching behavior, so that images are also loaded when there is no network available? Pointers to documentation regarding the caching would be very helpful as well.

like image 830
thumbmunkeys Avatar asked Jun 23 '13 13:06

thumbmunkeys


People also ask

What is image caching?

Image caching essentially means downloading an image to the local storage in the app's cache directory (or any other directory that is accessible to the app) and loading it from local storage next time the image loads.

Should images be cached?

Generally yes, images should be cached in at least memory, and depending on your app (how likely is it to be reused,etc) in memory and storage. If you want to support your 3rd point (displaying when offline), you need to do storage caching, and memory caching is optional but probably a good idea.

Why do we cache images?

The main benefit of caching an image service is to improve its performance. The cached image service can display an image very fast because ArcGIS Server does not have to generate the image dynamically.

Are images cached in browser?

A browser or Web cache does exactly that, except with program and website assets. When you visit a website, your browser takes pieces of the page and stores them on your computer's hard drive. Some of the assets your browser will store are: Images - logos, pictures, backgrounds, etc.


2 Answers

I have got a solution for you. It is JetImageLoader, I created it for application, where we need to load, cache and show big amount of logos, icons and so on.

It can be used as binding converter, so you should not even change your code! Just update your XAMLs!

Please, check out samples in repository, you'll love it ;)

Features:

  • Caching on disk
  • Caching in memory
  • Fully asynchronous
  • Available as binding converter or programmatically from your code
  • Fully open source, fork and improve it!

Here is the example:

<Image Source="{Binding ImageUrl, Converter={StaticResource MyAppJetImageLoaderConverter}}"/>
like image 137
Artem Zinnatullin Avatar answered Oct 21 '22 17:10

Artem Zinnatullin


BitmapImage automatically caches remote images by default. It's best used in conjunction with CreateOptions="BackgroundCreation" for the best performance.

<Image Height="100" Width="100" Margin="12,0,9,0">
  <Image.Source>
    <BitmapImage UriSource="{Binding ImgURL}" CreateOptions="BackgroundCreation"/>
  </Image.Source>
</Image>

This MSDN blog post, old but still relevant, lists and explains all the CreationOptions and that caching is automatic in most modes.

I use these options to display many news items with images and it works well. I can load the list of articles, exit the app and turn Flight Mode to On, then start a new instance of the app and the images still load up.

Manual Approach

If you'd like to control the caching yourself and cache HTTPS resources then there are few good examples...

  • ImgCache from the iFixit app
  • Value converter that downloads and saves images
  • PersistentImageCache from the Kawagoe Toolkit (may need updating to work with WP 7.5 or 8)
like image 43
Neil Turner Avatar answered Oct 21 '22 19:10

Neil Turner