Silverlight 3 を使用してユーザー イメージを読み込んでいます。すべて正常に動作し、ファイル ストリームを に設定すると、正常BitmapImage
にレンダリングされます。
問題は、画像ではないもの (.png に名前が変更された .exe など) を読み込もうとすると、Silverlight がクラッシュし、System.Exception
「壊滅的な失敗」というメッセージが表示されることです。MSDNのドキュメントには、msdnリンクがあり、イベントをリッスンする必要があると書かれていImageFailed
ます(これは決して発生しません)。
ストリームからロードするときにライブラリが壊れているのでしょうか?
ソースから画像をロードするコード:
var openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "*.jpg;*.jpeg;*.png|*.jpg;*.jpeg;*.png";
openFileDialog.Multiselect = false;
var showDialog = openFileDialog.ShowDialog();
if (showDialog.HasValue && showDialog.Value)
{
using (var reader = openFileDialog.File.OpenRead())
{
var picture = new BitmapImage();
picture.DownloadProgress += (o, e) => System.Threading.SynchronizationContext.Current.Send((oo) => System.Windows.Browser.HtmlPage.Window.Alert("Download progress: " + e.Progress), null);
picture.ImageFailed += (o, e) => System.Threading.SynchronizationContext.Current.Send((oo) => System.Windows.Browser.HtmlPage.Window.Alert("Image failed: " + e.ErrorException), null);
picture.ImageOpened += (o, e) => System.Threading.SynchronizationContext.Current.Send((oo) => System.Windows.Browser.HtmlPage.Window.Alert("Image opened: " + e.OriginalSource), null);
picture.SetSource(reader); // BANG! here without any of the alerts showing up
}
}