O'Reilly logo

Graphics Programming with GDI+ by Mahesh Chand

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.2. Cautions for Using GDI in Managed Code

We just saw how we can take advantage of services provided by the .NET runtime, which include the flexibility of mixing GDI with GDI+ and using GDI functionality in managed applications.

14.2.1. No GDI Calls between GetHdc and ReleaseHdc

GDI+ currently has no support for raster operations. When we use R2_XOR pen operations, we use the Graphics.GetHdc() method to get the handle to the device context. During the operation when your application uses the HDC, the GDI+ should not draw anything on the Graphics object until the Graphics.ReleaseHdc method is called. Every GetHdc call must be followed by a call to ReleaseHdc on a Graphics object, as in the following code snippet:

 IntPtr hdc1 = g1.GetHdc(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required