Graphics in the .NET Framework with Visual Basic

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

The .NET Framework provides the GDI+ application programming interface (API) for manipulating graphics. GDI+ is an advanced implementation of the Windows Graphics Device Interface (GDI). With GDI+ you can create graphics, draw text, and manipulate graphical images as objects. 

GDI+ is designed to offer performance, as well as ease of use. You can use GDI+ to render graphical images on Windows Forms and controls. Although you cannot use GDI+ directly on Web Forms, you can display graphical images through the Image Web Server control.

Introduction to GDI+

When you create a Windows Forms control, you can use GDI+ to access and update its image. You can also use GDI+ to create your own images, independent of your application's user interface.

To draw on an image in .NET Framework, you must use the Graphics object associated with the image.

In some cases, you can directly get the image's Graphics object. For example, when you are creating a Windows Forms control, you can override the OnPaint method to access the Graphics object for the control's image.

In other cases, such as when you are creating your own image, you also need to create a graphics object. The shared FromImage method takes an image and returns a Graphics object associated with that image.

The Graphics class has many drawing- and image-manipulation methods. Some of the commonly used methods are listed below:

Several of the methods listed above take as arguments structures or classes defined in the System.Drawing namespace. The following table lists some of the most used GDI+ classes and structures.

Class/Structure

Description

System.Drawing.Bitmap

Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes. A Bitmap is an object used to work with images defined by pixel data.

System.Drawing.Brushes

Defines brushes for all the standard colors.

System.Drawing.Color

Represents an ARGB color.

System.Drawing.Font

Defines a particular format for text, including font face, size, and style attributes.

System.Drawing.Pen

Defines an object used to draw lines and curves.

System.Drawing.Pens

Defines pens for all the standard colors.

System.Drawing.Point

Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.

System.Drawing.Rectangle

Stores a set of four integers that represent the location and size of a rectangle. For more advanced region functions, use a Region object.

System.Drawing.SolidBrush

Defines a brush of a single color. Brushes are used to fill graphics shapes, such as rectangles, ellipses, pies, polygons, and paths.

System.Drawing.TextureBrush

Each property of the TextureBrush class is a Brush object that uses an image to fill the interior of a shape.

Resource Management

Many of the drawing classes implement IDisposable because they encapsulate unmanaged system resources. If you create a new instance of one of these classes, you should call the class's Dispose method when you are through with the object.

Alternatively, you can create the object with the Using statement, which implicitly calls the object's Dispose method. For more information, see Object Lifetime: How Objects Are Created and Destroyed and Using Statement (Visual Basic).

See Also

Reference

System.Drawing

Using Statement (Visual Basic)

Concepts

Object Lifetime: How Objects Are Created and Destroyed