Reputation: 10087
I'm using the following code to load an image from file into a bitmap image class to display to the user at a particular size:
BitmapImage resized = new BitmapImage();
FileStream fs = new FileStream(ImageSource, FileMode.Open);
MemoryStream ms = new MemoryStream();
fs.CopyTo(ms);
fs.Close();
resized.BeginInit();
resized.CacheOption = BitmapCacheOption.OnDemand;
resized.DecodePixelHeight = (int)(_imageBaseHeight * zoomRate);
resized.DecodePixelWidth = (int)(_imageBaseWidth * zoomRate);
resized.StreamSource = ms;
resized.EndInit();
ImageDisplay = resized;
The problem is that sometimes, on particularly large images, this will fail silently and display a blank image without raising an exception. Is there a flag that I can check after EndInit() to be sure the image has loaded?
Upvotes: 1
Views: 1843