Hi,
I'm loading user images using Silverlight 3.
Everything works fine and I can set the file stream to a BitmapImage
and it gets rendered OK.
The problem is that if I try to load something that's not an image (like a .exe that's been renamed to .png) Silverlight crashes with a System.Exception
that says "Catastrophic failure".
The MSDN documentation unhelpfully says that it should be so there msdn link and I should listen to the ImageFailed
event (which never gets fired).
Am I missing something there or is the library broken when loading from a stream?
The code I've got loading the image from the source:
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
}
}