This article has been
excerpted from book "Graphics Programming with GDI+".
During the life cycle of a Graphics object, the object maintains a list of
graphics states. These graphics states fall into various categories depending on
the operations being applied to the Graphics object. For example, setting the
compositing quality of a Graphics object changes the object's state.
Graphics states can be divided into three categories:
- Quality setting
- Transformations
- Clipping region
The first state of the Graphics object involves
the quality of shapes and images. This state changes when you set the quality of
a Graphics object using the SmoothingMode, TextRenderingHint, CompositingMode,
CompositingQuality, and InterpolationMode properties of the Graphics class.
Transformation is another state that a Graphics object maintains. Transformation
is the process of changing graphics object from one state to another by
rotation, scaling, reflection, translation, and shearing.
The Graphics object maintains two transformation states: world and page. The
world transformation defines the conversion of world coordinates to page
coordinates. World coordinates are coordinates that you define in your program,
and page coordinates are coordinates that GDI+ uses to expose the object
coordinates. The page transformation defines the conversion of page coordinates
to device coordinates. Device coordinates determine how a graphics object will
be displayed on a particular display device.
The Graphics class provides the ScaleTransform, RotateTransform, and
TranslateTransform methods, as well as the Transform property, to support
transformations.
The world unit (by default) is always defined as a pixel. For example, in the
following code snippet a rectangle will be drawn starting at 0 pixels from the
left edge and 0 pixel from the top edge, with width and height of 100 and 50
pixels, respectively.
Graphics g = this.CreateGraphics();
g.DrawRectangle(Pens.Green, 0, 0, 100, 50);
Page coordinates may be different from world coordinates, depending on the page
unit and page scaling of the Graphics object. For example, if the page unit is
an inch, the page coordinates will start at point (0, 0) but the width and
height of the rectangle will be 100 inches and 50 inches, respectively.
TABLE 9.9: GraphicsUnit members
|
Member |
Description |
|
Display |
1/75 inch as the unit of measure. |
|
Document |
The document unit (1/300 inch) as the unit of measure. |
|
Inch |
An inch as the unit of measure. |
|
Millimeter |
A millimeter as the unit of measure. |
|
Pixel |
A pixel as the unit of measure. |
|
Point |
A printer's point (1/72 inch) as the unit of measure. |
|
World |
The world unit as the unit of measure. |



Join the conversation! Your thoughts help the community grow.