tags:

views:

62

answers:

2

Im tying together two libraries. One only gives output of type System.Windows.Media.Imaging.BitmapSource, the other only accepts input of type System.Drawing.Image. I havent been able to find a way to convert a BitmapSource to a Image.

A: 

I think you may find a code sample to do that here: http://stackoverflow.com/questions/2284353/is-there-a-good-way-to-convert-between-bitmapsource-and-bitmap

What do you think about it?

samy
+1  A: 
private System.Drawing.Bitmap BitmapFromSource(BitmapSource bitmapsource)
{
  System.Drawing.Bitmap bitmap;
  using (MemoryStream outStream = new MemoryStream())
  {
    BitmapEncoder enc = new BmpBitmapEncoder();
    enc.Frames.Add(BitmapFrame.Create(bitmapsource));
    enc.Save(outStream);
    bitmap = new System.Drawing.Bitmap(outStream);
  }
  return bitmap;
}
John Gietzen