World, Page, and Device Coordinates C# Help

The distinction between measuring position relative to the top-left corner of the document and measuring it relative to the top-left comer of the screen (desktop) is so important that GDI+ has special names for these coordinate systems:

  1. World coordinates specify the position of a point measured in pixels from the top-left corner of the document.
  2. Page coordinates specify the position of a point measured in pixels from the top-left corner of the client area.

Developers familiar with GDI will note that world coordinates correspond to what in GDI were known as logical coordinates, Page coordinates correspond to what were known as device coordinates, As a developer familiar with GDI, you should also note that the way you code conversion between logical and device coordinates has <hanged in GDI+ ln GDI, conversions took place via the device context, using the LP to DP () and DP to LP () Windows APl functions ln GDI+, it is the Control class from which both Form and all the various Windows Forms controls derive, that maintains the information needed to carry out the conversion.

GDI+ also distinguishes a third coordinate system, which is now known as decicde coordinates, Device coordinates are similar to page coordinates, except that you do not use pixels as the unit of measurement Instead, you use some other unit that can be specified by the user by calling the Graphics, Page Unit property, Possible units, besides the default of pixels, include inches and millimeters. Although you will not use the Page Unit property in this chapter, you might find it useful as a way of getting around the different pixel densities of devices. For example, 100 pixels on most monitors will occupy approximately an inch, However, laser printers can have 1,200 or more dpi (dots per inch), which means that a shape specified to be 100 pixels wide will look a lot smaller when printed. By setting the units to, say, inches and specifying that the shape should be 1 inch wide, you can ensure that the shape will look the same size on the different devices. This is illustrated in the following:

Graphics dc = this.CreateGraphics();
dc.PageUnit = GraphicsUnit.lnch;

Possible units available via the Graphics Unit enumeration include the following:

  1. Display – Defines the display’s unit measure
  2. Document – Defines the document unit (1/300 inch) as the unit of measure
  3. Inch – Defines the inch measurement as the unit of measure
  4. Millimeter – Defines the millimeter measurement as the unit of measure
  5. Pixel- Defines the pixel measurement as the unit of measure
  6. Point – Defines the printer point (1/72 inch) as the unit of measure
  7. World – Defines the world coordinate system as the unit of measure

Posted on November 2, 2015 in Graphics with GDI+

Share the Story

Back to Top
Share This