时间:2010-07-26 14:33:43

标签: c# bytearray bitmapimage

2 个答案:

答案 0 :(得分:8)

尝试这样的事情:

BitmapImage GetImage( byte[] rawImageBytes )
{
    BitmapImage imageSource = null;

    try
    {
        using ( MemoryStream stream = new MemoryStream( rawImageBytes  ) )
        {
            stream.Seek( 0, SeekOrigin.Begin );
            BitmapImage b = new BitmapImage();
            b.SetSource( stream );
            imageSource = b;
        }
    }
    catch ( System.Exception ex )
    {
    }

    return imageSource;
}

答案 1 :(得分:0)

使用此方法 首次使用

using System.IO;
using System.Windows.Media.Imaging;

,然后

 public Image Base64ToImage(byte[] imageBytes)
       {
           Image img = new Image();
           using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
           {
               BitmapImage im = new BitmapImage();
               im.SetSource(ms);
               img.Source = im;
           }
           return img;
       }