WPF:System.Windows.Interop.InteropBitmap到System.Drawing.Bitmap

时间:2011-04-04 09:23:35

标签: wpf c#-4.0 interop bitmap

有没有办法将System.Windows.Interop.InteropBitmap转换为System.Drawing.Bitmap?

谢谢

3 个答案:

答案 0 :(得分:2)

我能够使用下面的代码解决我的问题。 msg.ThumbnailSource包含System.Windows.Interop.InteropBitmap对象类型

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

答案 1 :(得分:0)

您可以使用CopyPixels获取像素,并使用the Bitmap.Lock/Unlock documentation中的代码将像素传递给位图。

答案 2 :(得分:0)

你能解释一下这个问题的背景吗? InteropBitmap是不是要在WPF中呈现传统位图元素?好像你正试图从win32 - > WPF - >的win32。