DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 14. The System.Drawing Namespace

The System.Drawing namespace contains the classes that make up the .NET implementation of GDI+—Microsoft's next-generation graphics architecture. If you are familiar with the C++ implementation shipped with Microsoft's Platform SDK, then you will recognize most of the classes found here. However, System.Drawing is not a wrapper around the C++ code; both are implemented in terms of a common, low-level graphics architecture, which at the time of writing has an unpublished API.

All drawing is carried out on a Graphics surface, using various kinds of Pen, Brush, and Image objects. You can control the Color (including transparency), Font, line style, and fill patterns of these objects, but the Graphics surface itself is responsible for the actual painting, providing methods such as DrawString(), DrawRectangle(), and FillClosedCurve() for this purpose. You can set up clipping Regions, control rendering styles such as antialiasing and compositing, or use a transform matrix (see System.Drawing.Drawing2D.Matrix) to rotate, scale, shear, and translate the drawing.

Usually, you will be supplied a Graphics surface on which to draw in the PaintEventArgs passed to your Control object's paint handler. However, you can also create surfaces from Control objects, Image objects (such as Bitmap and Metafile), or native GDI device contexts (through interop).

Because there are no objects that represent the drawing operations themselves, you cannot simply persist an object graph to store your drawing. .NET offers two other options, both of which have their limitations. First, you can save a Bitmap to a stream or file using the standard raster graphics encoders (e.g., BMP, PNG, JPG) by calling one of the Save() methods. Alternatively, you can use the Metafile support in System.Drawing.Imaging to store and restore a scalable, vectorized version of your drawing operations. At the present time, it is not possible to write your own encoders, but this may be possible in future versions of the platform.

The System.Drawing.Drawing2D contains classes that offer enhanced vector graphics support (such as the Matrix transforms), and System.Drawing.Imaging provides classes that offer enhanced imaging facilities (such as color transforms and direct pixel data access). Printing support can be found in System.Drawing.Printing.

Figure 14-1 shows many of the types in this namespace, and Figure 14-2 shows various converters.

Figure 14-1. Many types from the System.Drawing namespace
figs/winf_1401.gif
Figure 14-2. Converters in the System.Drawing namespace
figs/winf_1402.gif
    [ Team LiB ] Previous Section Next Section