On a WPF project, I need to set a ImageSource property from a local Resource. I am trying to use the following code:
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri("pack://application:,,,/Resources/Identicons/no_user.jpg", UriKind.Absolute);
bmp.EndInit();
Avatar = bmp;
Where Avatar is defined before as:
private ImageSource myAvatar;
The problem is that BitmapImage does not support MetaData information, that the source image have (it was created with Paint.net) so it throws a error. The error is the following:
Metadata = 'bmp.Metadata' threw an exception of type 'System.NotSupportedException'
So I believe that I need alternatives to BitmapImage to properly load the desired image.
As a end note, using the same image inside xaml, directly in a "source" property it works fine. Thank you