0
为什么当发生ArgumentException是因为image.jpg具有无效的元数据标头时,第一个示例是否捕获该异常,而第二个示例没有?使用BitmapImage.BeginInit()时未捕获ArgumentException()
实施例1:
try
{
Uri myUri = new Uri("http://example.com/image.jpg", UriKind.RelativeOrAbsolute);
JpegBitmapDecoder decoder2 = new JpegBitmapDecoder(myUri,
BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.Default);
BitmapSource bitmapSource2 = decoder2.Frames[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
实施例2:
try
{
BitmapImage src = new BitmapImage();
src.BeginInit();
src.UriSource = new Uri("http://example.com/image.jpg");
src.EndInit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
我将BitmapImage设置为边界上的Background属性,但那是我检查的第一件事。即使我没有将图像设置为异常仍然发生的原因。 – 2011-04-15 22:36:16
要说清楚,你是说这两个例子都抛出了一个异常,但例2中没有发现异常? – RandomEngy 2011-04-15 23:02:15
是的。当图像被加载出现问题时,它们都会抛出异常,但例外2中没有发现异常。 – 2011-04-15 23:32:37