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.
NOTE
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.
FIGURE 1.3: The GDI+ namespaces in the .NET Framework Library
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 use
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 s specified color.
Table 1.1 briefly describes the classes of the System.Drawing namespace.
The System.Drawing namespace also contains some structures that we will be using
throughout the article. These structures are CharacterRange, Color, Point,
PointF, Rectangle, RectangleF, Size, and SizeF.
TABLE 1.1: System.Drawing classes
Class | Description |
Bitmap | Encapsulates a bitmap, which is an image (with its properties) stored in pixel format. |
Brush | An abstract base class that cannot be instantiated directly. The Brush class provides functionality used by its derived brush class and represents a brush graphics object. A brush is used to fill the interior of a graphical shape with a specified color. |
Brushes | 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. |
ColorConverter | Provides methods and properties to convert colors from one type to another. |
ColorTranslator | Provides various methods to translate color from one type to another. |
Font | 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. |
Fontconverter | Provides members that convert fonts from one type to another. |
FontFamily | Defines a group of typefaces having a similar basic design and certain variations in styles. |
Graphics | A key class that encapsulates drawing surfaces. Among many other things, the Graphics class provides members to draw and fill graphical objects. |
Icon | Represents a Window icon. The Icon class provides members to define the size, width, and height of an icon. |
IconConverter | Provides members to convert an Icon object from one type to another. |
Image | 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 though its derived classes: Bitmap, Icon, and Metafile. |
ImageAnimator | Provides methods to start and stop animation, and to update frames for an image that has time-based frames. |
ImageConvertor | Provides members to convert Image objects from one type to another. |
ImageFormatConvertor | Defines members that can be used to convert images from one format to another. |
Pen | Define 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. |
Pens | Provides static members for all the standard colors. For example, Pens.Red represents a red pen. |
PointConverter | Defines members that can be used to convert Point objects from one type to another. |
Rectangle.Converter | Defines members that can be used to convert Rectangle objects from one type to another. |
Region | Represents a region in GDI+, which describes the interior of a graphic shape. |
SizeConverter | Defines members that can be used to convert size from one type to another. |
SolidBrush | Inherited from the Brush class. This class defines a solid brush of a single color. |
StringFormat | Provides members to define text format, including alignment, trimming and line spacing, display manipulations, and OpenType features. |
SystemBrushes | Defines static properties. Each property is a SolidBrush object with a Windows display element such as Highlight, HighlightText, or ActiveBorder. |
SystemColors | Defines static properties of a Color structure. |
SystemIcons | Defines static properties for Windows systemwide icons. |
SystemPens | Defines static properties. Each property is a Pen object with the color of a Windows display element and a width of 1. |
TextureBrush | Inherited from the Brush class. This class defines a brush that has an image as its texture. |
ToolboxBitmapAttribute | Defines the images associated with a specified component. |
The System.Drawing.Design Namespace
As its name suggest, 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.
Beside the classes discussed in Table 1.2, the System.Drawing.Design namespace
also define a few interfaces, delegates, and enumerations. Table 1.3 lists the
interfaces defined in the namespace.
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.
Beside the classes discussed in Table 1.4, the System.Drawing.Drawing2D
Namespace provides dozens of enumerations.
The System.Drawing.Imaging Namespace
Basic imaging functionality is defined in the System.Drawing.Imaging 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.
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.
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.
TABLE 1.2: System.Drawing.Design classes
Class | Description |
BitmapEditor | User interface (UI) for selecting bitmaps using a Properties window. |
CategoryNameCollection | Collection of categories. |
FontEditor | UI for selecting and configuring fonts. |
ImageEditor | UI for selecting images in a Properties window. |
PaintValueEventArgs | Provides data for the PaintValue event. |
PropertyValueUIItem | Provides information about the property value UI for a property. |
ToolboxComponents- CareatedEventArgs | Provides data for the ComponentsCreated event, which occurs when components are added to the toolbox. |
ToolboxComponents-CreateingEventArgs | Provides data for the ComponentsCreating event, which occurs when components are added to the toolbox. |
Toolbox Item | Provides a base implementation of a toolbox item. |
ToolboxItemCollection | Collection of toolbox items. |
UITypeEditor | Provides a base class that can be used to design value editors. |
TABLE 1.3: System.Drawing.Design Interfaces
Interface | Description |
IPopertyValueUIService | Manages the property list of the Properties windows. |
ItoolboxService | Provides access to the toolbox. |
ItoolboxUSer | Test the toolbox for toolbox item support capabilities and selects the current tool. |
TABLE 1.4: System.Drawing.Drawing2D Classes
Class | Description |
AdjustableArrowCap | 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. |
Blend | Gradient blends are used to provide smoothness and shading to the interiors of shapes. A blend patter contains factor and pattern arrays, which define the position and percentage of colors 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. |
ColorBlend | Define color blending in multicolor gradients. The Color and Position properties represent the color array and position array, respectively. |
CustomLineCap | Encapsulates a custom, user-defined line cap. |
GraphicsContainer | Represents the data of a graphics container. A graphics container is created by Graphics. BeginContainer followed by a call to Graphics.EndContainter. |
GraphicsPath | 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. |
GraphicsPathIteratpr | 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. |
GraphicsState | Represents the state of a Graphics object. |
HatchBrush | Hatch brushes are brushes with a hatch style, a foreground color, and a background color, This class represents a hatch brush in GDI+ |
LinerGradientBrush | Represents a brush with a linear gradient. |
Matrix | Encapsulates a 3x3 matrix that represents a geometric transformation. This class defines methods for inverting, multiplying, resetting, rotating, scaling, shearing, and translating matrices. |
PathData | 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. |
PathGradientBrush | 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. |
RegionData | 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
Class | Description |
BitmapData | 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. |
ColorMap | Defines a map for converting colors. ColorMap is used by the ImageAttributes class. |
ColorMatrix | Defines a 5x5 matrix that contains coordinates for the ARGB space. ColorMatrix is used by the ImageAttributes class. |
ColorPalette | Defines an array of colors that make up a color palette. ColorPalette is used by the ImageAttributes class. |
Encoder | Represents an encoder, which represents a globally unique identifier (GUID) that identifies the category of an image encode parameter. Encoder is used by the EncoderParameter class. |
EncoderParameter | An encoder parameter, which sets value for a particular category of an image. This class is used in the Save method with the help of EncoderParameters. |
EncoderParameters | An array of EncoderParameter objects. |
FrameDimension | Provides properties to get the frame dimensions of an image. |
ImageAttributes | Contains information about how image colors are manipulated during rendering. |
ImageCodecInfo | Retrieves information about the installed image codes. |
ImageFormat | Specifies the format of an image. |
Metafile | Defines a graphic metafile, which contains graphics operations in the form of records that can be recorded (constructed) and played back (displayed). |
MetafileHeader | Stores information about a metafile. |
MetaHeader | Contains information about a Windows-format (WMF) metafile. |
PropertyItem | Encapsulates a metadata property to be included in an image file. |
WmfPlaceableFileHeader | Defines a placeable metafile. |
TABLE 1.6: System.Drawing.Printing Classes
Class | Description |
Margins | Specifies the margins of a painted 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. |
MarginsConverter | Provides methods to convert margins, including CanConvertForm, CanConvertTo, ConvertFrom, and ConverTo. |
PageSettings | Specifies settings of a page, including properties such as Bounds, Color, Landscape, Margins, PaperSize, Papersource, PrinterResoultions, and PrinterSettings. |
PaperSize | 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. |
PaperSource | 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. |
PreviewPageInfo | 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. |
PreviewPrintController | 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. |
PrintController | Controls how a document is printed. The class provides four methods: OnStartPage, OnStartPrint, OnEndPage, and OnEndPrint. |
PrintDocument | 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. |
PrinterResolution | 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. |
PrinterSettings | Provides methods and properties for setting how a document is printed, including the printer that prints it. Some of the common properties are MinimumPage, MaxmimumPage, Copies, MaximumCopies, PrinterName, and so on. |
PrinterSettings.Paper-SizeCollection | Collection of PaperSize objects. |
PrinterSettings.Paper-SourceCollection | Collection of PaperSource objects. |
PrinterSettings.Printer-ResolutionCollection | Collection of PrinterResolution objects. |
PrinterUnitConvert | Specifies a series of conversion methods that are useful when interoperating with the Win32 printing application program interface (API). |
PrintEventArgs | Provides data for the BeginPrint and EndPrint events. |
PrintingPermission | Controls access to printers. |
PrintingPermission-Attribute | Allows declarative printing permission checks. |
PrintPageEventArgs | Provides data for the PrintPage event. |
QueryPageSettings-EventArgs | Provides data for the QueryPageSettings event. |
StandardPrintController | Specifies a print controller that sends information to a printer. |
TABLE 1.7: System.Drawing.Text Classes
Class | Description |
Fontcollection | 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. |
InstalledFontCollection | Represents the fonts installed on the system. |
PrivateFontCollection | Represents a collection of font families built from font files that are provided by the client application. |
GDI+ is an improved version of Microsoft's graphics device interface (GDI) API.
In this article we learned how GDI+ is designed for use in both managed and
unmanaged code.
System.Drawing and its helper namespaces designed in the .NET Framework library
provide a managed class wrapper to write managed GDI+ applications. We also
learned the basic and definition of GDI+ and what major improvements are offered
by GDI+ in comparison to GDI. At the end of this article, we took a quick look
at the System.Drawing namespace and its subnamespaces, and classes defined in
these namespaces.
Conclusion
Hope this article has helped you in understanding GDI+ Namespaces and Classes in
.NET. Read my other articles on GDI+ on this site.