我尝试在圈子中使用BitmapImage类的实例,但有时我会收到BitmapImage未初始化的错误消息。如何在使用之前检查BitmapImage是否已初始化?
答案 0 :(得分:0)
工作位图时常用2个事件,图像成功打开时发生1次火灾,图像失败时发生另一次火灾;
var myImage = new BitmapImage(new Uri(@"Images/img.jpeg",UriKind.Relative));
myImage.ImageOpened += myImage_ImageOpened;
myImage.ImageFailed += myImage_ImageFailed;
void myImage_ImageFailed(object sender, ExceptionRoutedEventArgs e)
{
//handle failed event
}
void myImage_ImageOpened(object sender, RoutedEventArgs e)
{
//handle Image Opend OK event
}