Since yesterday, i am trying to load an image from a byte array. I get the byte array from the Employees table of NorthWind database. I read some articles saying that there is an OLE header of size 78 that should be removed before we convert from byte[] to ImageSource. But it can't get any image. here is my converter:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
byte[] data = value as byte[];
if (data != null)
{
MemoryStream ms = new MemoryStream();
int offset = 78;
BitmapImage img = new BitmapImage();
ms.Write(data, offset, data.Length - offset);
img.SetSource(ms);
ms.Close();
return img;
}
return null;
}
here is my image definition in XAML
<Image Grid.Column="1" Height="147" HorizontalAlignment="Left" Margin="3,3,0,6" Name="photoImage" Source="{Binding Path=Photo, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource PhotoConverter1}}" Stretch="Fill" VerticalAlignment="Center" Width="137" DataContext="{Binding}" />
Could you help me to figure out how to make it work?