Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the GDI+ drawing in WPF?

Tags:

wpf

graphics

gdi+

I want to use the GDI+ drawing in my WPF control.

like image 592
Sreenath Avatar asked Oct 22 '09 04:10

Sreenath


2 Answers

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.

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

like image 147
Jeremiah Morrill Avatar answered Sep 27 '22 21:09

Jeremiah Morrill


Try compositing a Windows Form User Control in your WPF project and encapsulate GDI+ drawing in it. See Walkthrough: Hosting a Windows Forms User Control by Using the WPF Designer

like image 41
John K Avatar answered Sep 27 '22 21:09

John K