Meet us at PRINT 19. Chicago, IL. Oct. 3 - 5.
This documentation is for the old version. Go to the latest Graphics Mill docs

Units Measure

Generally when working with digital images and it is necessary to work with coordinates or dimensions, pixels are used as units. However it is not always convenient. Sometimes it would be preferable to work with physical units such as inches, centimeters, etc.

Resolution and DPI

Let's assume that you need to generate a business card, which has size 3.5x2 inches. How much pixels will it take? How to specify how image should be scaled during printing? To solve these questions, images have parameters which is called resolution - a number of pixels per some physical unit. As usual resolution is measured in DPI (dots per inch) - amount of pixels per one inch. Generally horizontal and vertical resolutions are equal, but sometimes they may differ.

How Does It Work?

Let's assume you need to create image with size 3.5x2 inches. First of all you should decide what resolution you need. The higher resolution, the better quality (more detailed image, less pixelization) but the high-resolution image is noticeable larger. As usual screen resolution is 72 or 96 DPI, scanned documents have 300 DPI. Note, printers have limited resolution (some printer cannot print more than 600 DPI, some professional models has capacity up to several thousands DPI). So it does not make sense to choose resolution which will not be reproduced by your printing device.

For definiteness let's use resolution 300 DPI. It means that 3.5x2 inches image will have width 3.5*300 = 1050 pixels and height 2*300 = 600 pixels. If we choosen 96 DPI, the width would be 3.5*96 = 336 pixels and height would be 2*96 = 192 pixels.

Not only image size can be measured in inches or other device-independent units. You can also measure all coordinates, sizes and other spatial parameters. All of them will depend on the resolution.

Resolution in Graphics Mill for .NET

Fortunately you never need to convert units to pixels and vica versa, Graphics Mill for .NET does it automatically. All you need is to specify the resolution for the image (or it can be read from the file along with other data) using HorizontalResolution and VerticalResolution properties of the Bitmap , and specify the unit to measure using Unit property. If you set other unit than Pixel, resolution will be used to interpret all the spatial arguments you pass to the bitmap methods. Also, class GdiGraphics has the same functionality, so you can draw lines, add text and so on using various metrics.

Here is a code example which creates new image with size 3.5x2 inches and adds text and graphics to it:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap

'Set unit to inches
bitmap.Unit = Aurigma.GraphicsMill.Unit.Inch

'Set resolution to 300 Dpi
bitmap.HorizontalResolution = 300
bitmap.VerticalResolution = 300

'Create new bitmap with size 3.5x2 inches
bitmap.Create(Aurigma.GraphicsMill.RgbColor.White, 3.5, 2, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

'Get graphics
Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = _
 bitmap.GetGdiGraphics()

'Create brush object
Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush( _
 Aurigma.GraphicsMill.RgbColor.Black)

'Create font object
Dim font As New Aurigma.GraphicsMill.Drawing.Font
font.Unit = bitmap.Unit
font.HorizontalResolution = bitmap.HorizontalResolution
font.VerticalResolution = bitmap.VerticalResolution
font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center

'Set font size to 0.4 inches
font.Size = 0.4
'Put text at coordinates 1.75, 0.1 in inches
graphics.DrawString("Aurigma", font, brush, 1.75F, 0.1F)

'Set font size to 0.3 inches
font.Size = 0.5
'Put text at coordinates 1.75, 0.7 in inches
graphics.DrawString("Graphics Mill", font, brush, 1.75F, 0.7F)

'Draw line 0.05 inches width
Dim pen As New Aurigma.GraphicsMill.Drawing.Pen( _
 Aurigma.GraphicsMill.RgbColor.Black, 0.05F)

graphics.DrawLine(pen, 0.0F, 1.5F, 3.5F, 1.5F)
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap();

//Set unit to inches
bitmap.Unit = Aurigma.GraphicsMill.Unit.Inch;

//Set resolution to 300 Dpi
bitmap.HorizontalResolution = 300;
bitmap.VerticalResolution = 300;

//Create new bitmap with size 3.5x2 inches
bitmap.Create(Aurigma.GraphicsMill.RgbColor.White, 3.5f, 2f,
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

//Get graphics
Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = 
    bitmap.GetGdiGraphics();

//Create brush object
Aurigma.GraphicsMill.Drawing.SolidBrush brush =
    new Aurigma.GraphicsMill.Drawing.SolidBrush( 
    Aurigma.GraphicsMill.RgbColor.Black);

//Create font object
Aurigma.GraphicsMill.Drawing.Font font =
    new Aurigma.GraphicsMill.Drawing.Font();
font.Unit = bitmap.Unit;
font.VerticalResolution = bitmap.VerticalResolution;
font.HorizontalResolution = bitmap.HorizontalResolution;

font.HorizontalAlignment =  
    Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center;

//Set font size to 0.4 inches
font.Size = 0.4f;
//Put text at coordinates 1.75, 0.1 in inches
graphics.DrawString("Aurigma", font, brush, 1.75F, 0.1F);

//Set font size to 0.3 inches
font.Size = 0.5f;
//Put text at coordinates 1.75, 0.7 in inches
graphics.DrawString("Graphics Mill", font, brush, 1.75F, 0.7F);

//Draw line 0.05 inches width
Aurigma.GraphicsMill.Drawing.Pen pen = new Aurigma.GraphicsMill.Drawing.Pen(
    Aurigma.GraphicsMill.RgbColor.Black, 0.05F);

graphics.DrawLine(pen, 0.0F, 1.5F, 3.5F, 1.5F);

Measurement Units in Graphics Mill for .NET

You can use not only inches as device-independent unit. Graphics Mill for .NET supports the following units:

  1. Pixels. Default unit, which means that all the spatial values are measured in pixels (device dependent). It is specified by the Pixel member of the Unit enumeration.
  2. Points. This unit is very popular to specify font size. Point is a 1/72 of inch (so 72 points is one inch). That's why when resolution is 72 DPI, it is the same as pixels. It is specified by the Point member of the Unit enumeration.
  3. Inches. This unit was discussed above. Specifies that all the spatial values are measured in inches. It is specified by the Inch member of the Unit enumeration.
  4. Document units. As scanned documents mainly have resolution 300 DPI, it is convenient to make special units which will specify one point on scanned document. This unit can be calculated as 1/300 of inch (in order to get resolution 300 DPI). It is specified by the Document member of the Unit enumeration.
  5. Millimeters. Sometimes it is convenient to use metric system of units instead of inches. That's why you can specify all the spatial parameters in millimeters. Millimeter is a 10/254 of inch (one inch contains 25.4 millimeters). It is specified by the Mm member of the Unit enumeration.
  6. Centimeters. Centimeter equals to 10 millimeters or 100/254 of inch. It is specified by the Cm member of the Unit enumeration.
  7. Meters. Meters equals to 1000 millimeters or 10000/254 of inch. It is specified by the M member of the Unit enumeration.
  8. Pica. It equals to 1/6 of the inch. It is specified by the Pica member of the Unit enumeration.
  9. Column. It equals to 100/263 of the inch. It is specified by the Column member of the Unit enumeration.
  10. Twips. This unit is mostly used when you need fine way to specify coordinates or other parameters measured in units. For example default unit in VB6 form designer are twips. It has very fine pitch - only 1/20 of point (or 1/1440 of inch). It is specified by Twip member of Unit enumeration.