I am a little confused as to this class, I was hoping someone could shed some light. I know that when it downloads depends on the BitmapCreateOptions of the image.

However, when you create an absolute BitmapImage, say:

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

It won't download it right away, because DelayCreation is the default BitmapCreateOptions, correct?

What if you do:

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

Will it start downloading the image immediately after you set its BitmapCreateOptions? If so, then this has the same behavior, correct?

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

Ok, now, how does caching work for BitmapImage?

  1. When does a BitmapImage get "cached"?
  2. Do only downloaded e.g. "absolute" images get cached or local e.g. "relative" images as well?
  3. When/how often does the cache get refreshed?
  4. Does this mean that I do not need to worry about manually caching the images in Isolated Storage my Windows Phone Project?

And, finally, when do the ImageOpened, and ImageFailed events get raised?

  1. Do they get raised only when a BitmapImage is downloaded?
  2. Or do they get raised when a BitmapImage is loaded from the cache?
  3. Or when they get rendered on a screen?
有帮助吗?

解决方案

I know this is months late but for the record, the download happens when EndInit is called, any other changes to properties after this is discarded. Using constructors other than the default constructor will automatically initialize the image.

In other words:

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

If you want to set a property you initialize manually like this:

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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top