2

从昨天开始,我正在尝试从字节数组中加载图像。我从NorthWind 数据库的雇员表中得到字节数组。我读过一些文章说在我们从 byte[] 转换为 ImageSource 之前应该删除一个大小为 78 的 OLE 标头。但它无法获得任何图像。这是我的转换器:

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;

    }

这是我在 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}" />

你能帮我弄清楚如何让它工作吗?

4

1 回答 1

0

http://en.wikipedia.org/wiki/BMP_file_format

您应该能够查看数组并使用位图中的标头信息查看位图从何处开始。

此代码也可以帮助您:http: //blogs.msdn.com/b/pranab/archive/2008/07/15/removing-ole-header-from-images-stored-in-ms-access-db-as -ole-object.aspx

于 2012-02-29T19:49:23.443 回答