Bitmap To BitmapImage - CSharp System.Windows.Media.Imaging

CSharp examples for System.Windows.Media.Imaging:BitmapImage

Description

Bitmap To BitmapImage

Demo Code


using System.Windows.Media.Imaging;
using System.IO;/*ww  w.j  av  a 2  s.  c  o  m*/
using System.Drawing.Imaging;
using System.Drawing;

public class Main{
        public static BitmapImage ToBitmapImage(this Bitmap bitmap)
        {
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, ImageFormat.Bmp);
            ms.Seek(0, SeekOrigin.Begin);
            bi.StreamSource = ms;
            bi.EndInit();
            return bi;
        }
}

Related Tutorials