I have this ValueConverter
to convert a byte[]
into a BitmapImage
:
public class ByteArrayToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var bitmapImage = new BitmapImage();
var buffer = (byte[])value;
var str = new MemoryStream(buffer).AsRandomAccessStream();
bitmapImage.SetSource(str);
return bitmapImage;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
Strangely enough, when I run the code, the application hangs (deadlocks) in the in the line with SetSource
.
Why is this happening? Am I doing something wrong?