Why the use of 'RenderTargetBitmap' class makes GDI handle count increase?

176 Views Asked by At

My understandings

1) The classes inside 'System.Windows.Media' uses directx for rendering. It will not use GDI+. 2) Only classes in 'System.Drawing' uses GDI+ for drawing.( This can cause GDI handle count increase.)

Issue

But when I use 'System.Windows.Media.Imaging.RenderTargetBitmap' for rendering a bitmap, the GDI count seems to be increased.

Why it happens so?

( Since I need to place these images on a button, and this button is part of the celltemplate of a Grid control, I want to reduce the GDI usage.)

DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
// Create Rectangle
Rect rect = new Rect(new System.Windows.Point(0, 0), new System.Windows.Point(100, 100));
// Draw Rectangle
System.Windows.Media.Pen pen = new System.Windows.Media.Pen();
pen.Brush = Brushes.Black;
pen.Thickness = 5;
drawingContext.DrawRectangle(Brushes.Black, pen, rect);             
drawingContext.Close();
RenderTargetBitmap bmp = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Pbgra32);
//Render DrawingVisual 
bmp.Render(drawingVisual);
1

There are 1 best solutions below

0
Sunil On BEST ANSWER

Looking around the net and some analysis, it seems that RenderTargetBitmap doesn't take advantage of hardware rendering(Direct X). It still uses GDI+ for rendering the bitmap offline.

It may be an exception to the common understanding about WPF rendering. But its surprise me that MSDN doesn't provide a clue anywhere regarding this.