我正在使用以下代码将图像从文件加载到位图图像类中,以便以特定大小显示给用户:
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;
问题在于,有时候,在特别大的图像上,这将无声地失败并显示空白图像而不会引发异常。是否有一个标志,我可以在EndInit()之后检查以确保图像已加载?