Drawing and Graphics Contexts

The GDI API provides functions for drawing and filling various shapes (points, lines, polylines, arcs, rectangles, polygons, ellipses, rounded rectangles and pie slices), for drawing text, and for drawing bitmaps. Each drawing operation has a number of settings that affect its function—pen style, fill style, typeface, etc. Instead of passing these settings as parameters to every drawing function, the GDI API has the concept of a graphics context (GC) in which drawing functions are performed. The CGraphicsContext class is used to hold these settings and to provide all of the graphics functionality.

The normal way of performing a drawing operation is therefore:

  1. Set up a graphics context to hold the settings.

  2. Call the graphics function of that context to perform the operation.

Graphics contexts are provided by graphics device objects that represents the medium being drawn to. The abstract base class for graphics device objects is CGraphicsDevice.

Related concepts