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.
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.
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.
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.
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.
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:
Here is the example:
<Image Source="{Binding ImageUrl, Converter={StaticResource MyAppJetImageLoaderConverter}}"/>
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With