簡體   English   中英

使用BitmapImage.BeginInit()時未捕獲ArgumentException

[英]ArgumentException not caught when using BitmapImage.BeginInit()

為什么當由於image.jpg具有無效的元數據頭而發生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);
}

它可能正在等待,直到請求圖像加載為止,例如被設置為Image控件的源。

如果您添加了它,可能會給您帶來例外

src.CacheOption = BitmapCacheOption.OnLoad;

您的聲明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM