编程语言
首页 > 编程语言> > c# – .NET FW BitmapImage类何时下载/缓存?

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();

标签:c,net,download,windows-phone-8,bitmapimage
来源: https://codeday.me/bug/20190708/1405408.html