微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – .NET FW BitmapImage类何时下载/缓存?

我对这堂课有点困惑,我希望有人可以解释一下.
我知道下载时取决于图像的 BitmapCreateOptions.

但是,当您创建绝对BitmapImage时,请说:

var Image = new BitmapImage(new Uri("http://...",UriKind.Absolute))

它不会马上下载,因为DelayCreation是认的BitmapCreateOptions,对吗?

如果你做了怎么办:

var Image = new BitmapImage(new Uri("http://...",UriKind.Absolute))
Image.CreateOptions = BitmapCreateOptions.None;

设置BitmapCreateOptions后会立即开始下载图像吗?
如果是这样,那么这有相同的行为,对吗?

var Image = new BitmapImage(new Uri("http://...",UriKind.Absolute)) { CreateOptions = BitmapCreateOptions.None }

好的,现在,缓存如何为BitmapImage工作?

> BitmapImage何时被“缓存”?
>只下载例如“绝对”图像被缓存或本地例如“相对”图像也是?
>缓存何时/多久刷新一次?
>这是否意味着我不需要担心手动缓存隔离存储我的Windows Phone项目中的图像?

最后,ImageOpenedImageFailed事件什么时候被提升?

>只有在下载BitmapImage时它们才会被提升吗?
>或者从缓存加载BitmapImage时它们会被引发吗?
>或者当它们在屏幕上呈现时?

解决方法

我知道这已经晚了几个月,但是对于记录,下载是在调用EndInit时发生的,在此之后对属性的任何其他更改都将被丢弃.使用认构造函数以外的构造函数自动初始化图像.

换一种说法:

var Image = new BitmapImage(new Uri("http://...",UriKind.Absolute));
// The image is Now intialized and is downloading/downloaded
Image.CreateOptions = BitmapCreateOptions.None; // nothing happens here

如果要设置属性,请手动初始化,如下所示:

var Image = new BitmapImage();

Image.BeginInit();
Image.UriSource = new Uri("http://...",UriKind.Absolute)
Image.CreateOptions = BitmapCreateOptions.None; // This is default anyway so it won't affect
// ..Setting other properties...
Image.EndInit();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐