I have been tackling this problem for some time. I get the image from my DB as a byte[] and i want to convert it to WritableBitmap so i can use binding to show it on my xaml
Thanks for your answer
It seems that the problem was that the stream coming from the db was corrupted somehow. the value converter was actually okay. i have changed it to use PictureDecoder.DecodeJpeg() instead so it will be more clean and dynamic
public class ImageConverter : IValueConverter
{
///
/// Converts a Jpeg byte array into a WriteableBitmap
///
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is byte[])
{
MemoryStream stream = new MemoryStream((Byte[])value);
WriteableBitmap bmp = PictureDecoder.DecodeJpeg(stream);
return bmp;
}
else
return null;
}
///
/// Converts a WriteableBitmap into a Jpeg byte array.
///
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}