gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:45:47 24 4
gpt4 key购买 nike

我对这门课有点困惑,我希望有人能给出一些启示。我知道它何时下载取决于 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 的缓存是如何工作的? ?

  1. BitmapImage 何时被“缓存”?
  2. 仅下载,例如“绝对”图像被缓存或本地化,例如也是“相对”图像?
  3. 缓存何时/多久刷新一次?
  4. 这是否意味着我不需要担心在我的 Windows Phone 项目中手动缓存独立存储中的图像?

最后,ImageOpened 什么时候执行? , 和 ImageFailed引发事件?

  1. 他们是否只有在出现 BitmapImage 时才被提升?下载了吗?
  2. 或者当 BitmapImage 时他们会被提升吗?从缓存中加载?
  3. 或者当它们在屏幕上呈现时?

最佳答案

我知道这已经晚了几个月,但为了记录,下载发生在调用 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 FW BitmapImage 类何时下载/缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22875866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com