图片来源和缓存 [英] Image Source and Caching

查看:227
本文介绍了图片来源和缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的代码来显示从一个web服务器的图像:

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

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

图片就会自动下载,我想也有基于URL的一些缓存。

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

我的问题是,当应用程序处于脱机状态,assumably缓存图像不显示。

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.

推荐答案

的BitmapImage 自动默认缓存远程图像。它的最佳结合 CreateOptions =BackgroundCreation使用以获得最佳性能。

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>

这个MSDN博客帖子,老但仍相关,列出并解释所有的 CreationOptions 和缓存在多数模式下自动进行的。

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.

手动方法

如果你想控制自己的缓存和缓存HTTPS资源然后有几个很好的例子...

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)

这篇关于图片来源和缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆