tags:

views:

251

answers:

4

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

+1  A: 

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

John K
Without using the WinForms is there is any way to use GDI+ drawing by using System::Drawing::Graphics class?
Sreenath
A: 

WPF comes with new graphics features, you can investigate it here, but if you want to use an old GDI+ API one way to do is to create Winform draw there and host it into WPF

ArsenMkrt
Without using the WinForms is there is any way to use GDI+ drawing by using System::Drawing::Graphics class?
Sreenath
You can write native interop using dllimport to GDI+
ArsenMkrt
Also http://stackoverflow.com/questions/271686/c-transition-between-gdi-and-wpf this post can help
ArsenMkrt
A: 

This is generally a bad idea. WPF is a completely new API and mixing in GDI+ may result in poor performance, memory leaks and other undesirable things.

Alastair Pitts
+1  A: 

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.

Jeremiah Morrill