且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在WPF中使用GDI +绘图?

更新时间:2023-02-26 16:42:25

有几种方法可以做到这一点,最简单将锁定您使用GDI操作的位图,获取像素缓冲区(Scan0 IntPtr位于从锁中获取的BitmapData中)。从您的像素缓冲区 CopyMemory(...) WriteableBitmap.BackBuffer

There are several ways to do this, the easiest would be to lock your Bitmap you manipulated with GDI, get the pixel buffer (Scan0 IntPtr in the BitmapData you get from the lock). CopyMemory(...) from you pixel buffer to a WriteableBitmap.BackBuffer.

WPF中有更多高性能的方式,如使用InteropBitmap而不是WriteableBitmap。但是这需要更多的p / invoke。

There are more performant ways in WPF, like using the InteropBitmap instead of WriteableBitmap. But that needs more p/invoke.