【问题标题】:When does the .NET FW BitmapImage class download/cache?.NET FW BitmapImage 类何时下载/缓存?
【发布时间】:2015-01-15 06:11:44
【问题描述】:

我对这门课有点困惑,我希望有人能解释一下。 我知道下载的时间取决于图片的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 项目的独立存储中手动缓存图像?

最后,ImageOpenedImageFailed 事件何时引发?

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

【问题讨论】:

  • 没有人知道图像缓存是如何工作的?大声笑

标签: c# .net windows-phone-8 download bitmapimage


【解决方案1】:

我知道这已经晚了几个月,但为了记录,下载发生在调用 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();

【讨论】:

    猜你喜欢
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    相关资源
    最近更新 更多