I want to use the GDI+ drawing in my WPF control.
@Jeremiah Morrill's solution is what you'd do at the core. However, Microsoft was nice enough to provide some interop methods:
using System.Windows.Interop;
using Gdi = System.Drawing;
using (var tempBitmap = new Gdi.Bitmap(width, height))
{
using (var g = Gdi.Graphics.FromImage(tempBitmap))
{
// Your GDI drawing here.
}
// Copy GDI bitmap to WPF bitmap.
var hbmp = tempBitmap.GetHbitmap();
var options = BitmapSizeOptions.FromEmptyOptions();
this.WpfTarget.Source = Imaging.CreateBitmapSourceFromHBitmap(hbmp,
IntPtr.Zero, Int32Rect.Empty, options);
}
// Redraw the WPF Image control.
this.WpfTarget.InvalidateMeasure();
this.WpfTarget.InvalidateVisual();