2

Is there a way to convert System.Windows.Interop.InteropBitmap to System.Drawing.Bitmap?

Thank you

xscape
  • 3,318
  • 9
  • 45
  • 86

2 Answers2

3

I was able to solve my problem using the code below. msg.ThumbnailSource contains System.Windows.Interop.InteropBitmap type of object

BitmapSource bmpSource = msg.ThumbnailSource as BitmapSource;
MemoryStream ms = new MemoryStream();
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmpSource));
encoder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);


System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(ms);
Itai Bar-Haim
  • 1,686
  • 16
  • 40
xscape
  • 3,318
  • 9
  • 45
  • 86
0

You could take the pixels using CopyPixels and use the code from the Bitmap.Lock/Unlock documentation to pass the pixels to the Bitmap.

Emond
  • 50,210
  • 11
  • 84
  • 115