且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

的Windows Phone 8 - 负载byte []数组与绑定XAML图像

更新时间:2023-10-10 21:31:22

下面是一个转换代码将转换您的字节[] 的BitmapImage

Here is the code for a Converter that will convert your byte[] into a BitmapImage:

public class BytesToImageConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value != null && value is byte[])
        {
            byte[] bytes = value as byte[];
            MemoryStream stream = new MemoryStream(bytes);
            BitmapImage image = new BitmapImage();

            image.SetSource(stream);

            return image;
        }

        return null;

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}