Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

public static BitmapImage ToBitmapImage(System.Drawing.

Image bitmap)
{
using (var memory = new MemoryStream())
{
bitmap.Save(memory, ImageFormat.Png);
memory.Position = 0;

var bitmapImage = new BitmapImage();


bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
bitmapImage.Freeze();

return bitmapImage;
}
}

private Bitmap BitmapImage2Bitmap(BitmapImage imgOrg)


{
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(imgOrg));
enc.Save(outStream);
Bitmap bitmap = new Bitmap(outStream);

return new Bitmap(bitmap);


}
}

You might also like