GDI+ Namespaces and Classes in .NET

In the .NET Framework library, six namespaces define managed GDI+: System.Drawing, System.Drawing.Design, System.Drawing.Drawing2D, System.Drawing.Imaging, System.Drawing.Printing, and System.Drawing.Text. Figure 1.3 shows these namespaces. To use any of the classes defined in these namespaces, you must include them in your application.

Figure 1.3. The GDI+ namespaces in the .NET Framework library



The .NET Framework class library is also referred as the .NET runtime class library or base class library (BCL).

This section will provide an overview of GDI+ namespaces, their contents, and why and when to use them. These classes and their members will be discussed in more detail in subsequent chapters, according to how they're categorized.


If you are already aware of the .NET Framework library's GDI+ objects and class hierarchy, you may want to skip the rest of this chapter.


1.4.1 The System.Drawing Namespace

The System.Drawing namespace defines basic GDI+ functionality. This namespace contains the Graphics class, which provides methods for filling and drawing graphics objects. It also provides classes that encapsulate GDI+ primitives such as rectangles, points, brushes, and pens. Brush and its derived classes are used to fill interiors of graphics objects such as ellipses, rectangles, and polygons with the specified color and pattern. The Pen class is used to draw lines and curves with a specified color.

Table 1.1 briefly describes the classes of the System.Drawing namespace. We will not discuss these classes in depth here; they are discussed in more detail in later chapters.

The System.Drawing namespace also contains some structures that we will be using throughout this book. These structures are CharacterRange, Color, Point, PointF, Rectangle, RectangleF, Size, and SizeF.

In addition, this namespace defines some delegates and enumerations, which we will discuss in later chapters.

Table 1.1. System.Drawing classes




Encapsulates a bitmap, which is an image (with its properties) stored in pixel format.


An abstract base class that cannot be instantiated directly. The Brush class provides functionality used by its derived brush classes and represents a brush graphics object. A brush is used to fill the interior of a graphical shape with a specified color.


Represents brushes with all the standard colors. This class has a static member for each standard color. For example, Brushes.Blue represents a blue brush.


Provides methods and properties to convert colors from one type to another.


Provides various methods to translate colors from one type to another.


Provides members to define the format of font text, name, face, size, and styles. The Font class also provides methods to create a Font object from a window handle to a device context or window handle.


Provides members that convert fonts from one type to another.


Defines a group of typefaces having a similar basic design and certain variations in styles.


A key class that encapsulates drawing surfaces. Among many other things, the Graphics class provides members to draw and fill graphical objects.


Represents a Windows icon. The Icon class provides members to define the size, width, and height of an icon.


Provides members to convert an Icon object from one type to another.


Provides members to define the size, height, width, and format of an image. The Image class also provides methods to create Image objects from a file, a window handle, or a stream; and to save, rotate, and flip images. It is an abstract base class, and its functionality is used through its derived classes: Bitmap, Icon, and Metafile.


Provides methods to start and stop animation, and to update frames for an image that has time-based frames.


Provides members to convert Image objects from one type to another.


Defines members that can be used to convert images from one format to another.


Defines a pen with a specified color and width. A pen is used to draw graphical objects such as a line, a rectangle, a curve, or an ellipse.


Provides static members for all the standard colors. For example, Pens.Red represents a red pen.


Defines members that can be used to convert Point objects from one type to another.


Defines members that can be used to convert Rectangle objects from one type to another.


Represents a region in GDI+, which describes the interior of a graphics shape.


Defines members that can be used to convert size from one type to another.


Inherited from the Brush class. This class defines a solid brush of a single color.


Provides members to define text format, including alignment, trimming and line spacing, display manipulations, and OpenType features.


Defines static properties. Each property is a SolidBrush object with a Windows display element such as Highlight, HighlightText, or ActiveBorder.


Defines static properties of a Color structure.


Defines static properties for Windows systemwide icons.


Defines static properties. Each property is a Pen object with the color of a Windows display element and a width of 1.


Inherited from the Brush class. This class defines a brush that has an image as its texture.


Defines the images associated with a specified component.

1.4.2 The System.Drawing.Design Namespace

As its name suggests, the System.Drawing.Design namespace provides additional functionality to develop design-time controls such as custom toolbox items, graphics editors, and type converters. The classes of the System.Drawing.Design namespace are described briefly in Table 1.2.

Besides the classes discussed in Table 1.2, the System.Drawing.Design namespace also defines a few interfaces, delegates, and enumerations. Table 1.3 lists the interfaces defined in this namespace.

1.4.3 The System.Drawing.Drawing2D Namespace

The System.Drawing.Drawing2D namespace defines functionality to develop advanced two-dimensional and vector graphics applications. This namespace provides classes for graphics containers, blending, advanced brushes, matrices, and transformation. Table 1.4 briefly describes these classes.

Besides the classes discussed in Table 1.4, the System.Drawing.Drawing2D namespace provides dozens of enumerations. We will discuss these enumerations when we use them in examples in later chapters.

1.4.4 The System.Drawing.Imaging Namespace

Basic imaging functionality is defined in the System.Drawing namespace. The System.Drawing.Imaging namespace provides functionality for advanced imaging. Before an application uses classes from this namespace, it must reference the System.Drawing.Imaging namespace.

Table 1.5 briefly describes the classes of the System.Drawing.Imaging namespace. These classes and their use are discussed in more detail in Chapter 8.

1.4.5 The System.Drawing.Printing Namespace

The System.Drawing.Printing namespace defines printing-related classes and types in GDI+. Before an application uses classes from this namespace, it must include the namespace.

Table 1.6 briefly discusses the classes provided by the System.Drawing.Printing namespace. These classes and their use are discussed in more detail in Chapter 11.

1.4.6 The System.Drawing.Text Namespace

The System.Drawing.Text namespace contains only a few classes related to advanced GDI+ typography functionality. Before an application uses classes from this namespace, it must include the namespace. Table 1.7 describes these classes; they will be discussed in more detail in Chapter 5.

Table 1.2. System.Drawing.Design classes




User interface (UI) for selecting bitmaps using a Properties window.


Collection of categories.


UI for selecting and configuring fonts.


UI for selecting images in a Properties window.


Provides data for the PaintValue event.


Provides information about the property value UI for a property.


Provides data for the ComponentsCreated event, which occurs when components are added to the toolbox.


Provides data for the ComponentsCreating event, which occurs when components are added to the toolbox.


Provides a base implementation of a toolbox item.


Collection of toolbox items.


Provides a base class that can be used to design value editors.

Table 1.3. System.Drawing.Design interfaces




Manages the property list of the Properties window.


Provides access to the toolbox.


Tests the toolbox for toolbox item support capabilities and selects the current tool.

Table 1.4. System.Drawing.Drawing2D classes




Represents an adjustable arrow-shaped line cap. Provides members to define the properties to fill, and to set the height and width of an arrow cap.


Gradient blends are used to provide smoothness and shading to the interiors of shapes. A blend pattern contains factor and pattern arrays, which define the position and percentage of color of the starting and ending colors. The Blend class defines a blend pattern, which uses LinearGradientBrush to fill the shapes. The Factors and Positions properties represent the array of blend factors and array of positions for the gradient, respectively.


Defines color blending in multicolor gradients. The Color and Position properties represent the color array and position array, respectively.


Encapsulates a custom, user-defined line cap.


Represents the data of a graphics container. A graphics container is created by Graphics.BeginContainer followed by a call to Graphics.EndContainer.


In GDI+, a path is a series of connected lines and curves. This class provides properties to define the path's fill mode and other properties. This class also defines methods to add graphics shapes to a path. For instance, the AddArc and AddCurve methods add an arc and a curve, respectively, to the path. Wrap, Transform, Reverse, and Reset are some of the associated methods.


A path can contain subpaths. This class provides the ability to find the number of subpaths and iterate through them. Count and SubpathCount return the number of points and the number of subpaths in a path, respectively.


Represents the state of a Graphics object.


Hatch brushes are brushes with a hatch style, a foreground color, and a background color. This class represents a hatch brush in GDI+.


Represents a brush with a linear gradient.


Encapsulates a 3x3 matrix that represents a geometric transformation. This class defines methods for inverting, multiplying, resetting, rotating, scaling, shearing, and translating matrices.


Contains the data in the form of points and types that makes up a path. The Points property of the class represents an array of points, and the Types property represents the types of the points in a path.


Represents a brush with a graphics path. PathGradientBrush contains methods and properties for blending, wrapping, scaling, and transformation. This class encapsulates a Brush object that fills the interior of a GraphicsPath object with a gradient.


Represents the data stored by a Region object. The Data property of this class represents the data in the form of an array of bytes.

Table 1.5. System.Drawing.Imaging classes




Often we don't want to load and refresh all data of a bitmap because rendering each pixel is not only a slow process, but also consumes system resources. With the help of the BitmapData class and its LockBits and UnlockBits methods, we can lock the required data of a bitmap in memory and work with that instead of working with all the data.


Defines a map for converting colors. ColorMap is used by the ImageAttributes class.


Defines a 5x5 matrix that contains coordinates for the ARGB space. ColorMatrix is used by the ImageAttributes class.


Defines an array of colors that make up a color palette. ColorPalette is used by the ImageAttributes class.


Represents an encoder, which represents a globally unique identifier (GUID) that identifies the category of an image encoder parameter. Encoder is used by the EncoderParameter class.


An encoder parameter, which sets values for a particular category of an image. This class is used in the Save method with the help of EncoderParameters.


An array of EncoderParameter objects.


Provides properties to get the frame dimensions of an image.


Contains information about how image colors are manipulated during rendering (for more information, see Chapter 7).


Retrieves information about the installed image codecs.


Specifies the format of an image.


Defines a graphic metafile, which contains graphics operations in the form of records that can be recorded (constructed) and played back (displayed).


Stores information about a metafile.


Contains information about a Windows-format (WMF) metafile.


Encapsulates a metadata property to be included in an image file.


Defines a placeable metafile.

Table 1.6. System.Drawing.Printing classes




Specifies the margins of a printed page. The Bottom, Left, Right, and Top properties are used to get and set the bottom, left, right, and top margins, respectively, of a page in hundredths of an inch.


Provides methods to convert margins, including CanConvertFrom, CanConvertTo, ConvertFrom, and ConvertTo.


Specifies settings of a page, including properties such as Bounds, Color, Landscape, Margins, PaperSize, PaperSource, PrinterResolution, and PrinterSettings.


Specifies the paper size. Its properties include Height, Width, PaperName, and Kind. The Kind property is the type of paper, represented by the PaperKind enumeration, which has members that represent A3, envelopes, sheets, ledgers, and so on.


Specifies the paper tray from which the printer gets paper, with properties Kind and SourceName. SourceName is a type of PaperSource enumeration, which defines members based on the Kind property.


Provides print preview information for a single page. The Image property returns the image of the printed page, and the PhysicalSize property returns the size of the printed page in 1/1000 inch.


Displays a document on a screen as a series of images for each page. The UseAntiAlias property gets and sets the anti-aliasing when displaying the print preview.


Controls how a document is printed. The class provides four methods: OnStartPage, OnStartPrint, OnEndPage, and OnEndPrint.


Starts the printing process. Creates an instance of this class, sets the printing properties that describe how to print, and calls the Print method to start the process.


Provides properties to return a printer resolution. The Kind, X, and Y properties return the printer resolution, horizontal resolution in dots per inch (dpi), and vertical printer resolution in dpi, respectively.


Provides methods and properties for setting how a document is printed, including the printer that prints it. Some of the common properties are MinimumPage, MaximumPage, Copies, MaximumCopies, PrinterName, and so on.


Collection of PaperSize objects.


Collection of PaperSource objects.


Collection of PrinterResolution objects.


Specifies a series of conversion methods that are useful when interoperating with the Win32 printing application program interface (API).


Provides data for the BeginPrint and EndPrint events.


Controls access to printers.


Allows declarative printing permission checks.


Provides data for the PrintPage event.


Provides data for the QueryPageSettings event.


Specifies a print controller that sends information to a printer.

Table 1.7. System.Drawing.Text classes




Abstract base class for installed and private font collections. It provides a method to get a list of the font families contained in the collection. Two derived classes from the FontCollection class are InstalledFontCollection and PrivateFontCollection.


Represents the fonts installed on the system.


Represents a collection of font families built from font files that are provided by the client application.

GDI+: The Next-Generation Graphics Interface

Your First GDI+ Application

The Graphics Class

Working with Brushes and Pens

Colors, Fonts, and Text

Rectangles and Regions

Working with Images

Advanced Imaging

Advanced 2D Graphics



Developing GDI+ Web Applications

GDI+ Best Practices and Performance Techniques

GDI Interoperability

Miscellaneous GDI+ Examples

Appendix A. Exception Handling in .NET

GDI+ Programming with C#
GDI+ Programming with C#
ISBN: 073561265X
Year: 2003
Pages: 145 © 2008-2020.
If you may any questions please contact us: