byte[] to BitmapImage in silverlight

无人久伴 提交于 2019-11-27 15:42:37

Try something like this:

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;
}

use this method first use

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

then

 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;
       }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!