【问题标题】:WPF: System.Windows.Interop.InteropBitmap to System.Drawing.BitmapWPF:System.Windows.Interop.InteropBitmap 到 System.Drawing.Bitmap
【发布时间】:2011-04-04 09:23:34
【问题描述】:

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

谢谢

【问题讨论】:

    标签: wpf c#-4.0 interop bitmap


    【解决方案1】:

    我能够使用下面的代码解决我的问题。 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);
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        您能否再解释一下问题的背景? InteropBitmap 不是要在 WPF 中呈现旧的位图元素吗?好像你正试图从 win32 -> WPF -> win32 去。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-04-10
          • 2012-07-20
          • 2014-06-24
          • 2011-04-25
          • 1970-01-01
          • 2019-07-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多