Click here to Skip to main content
15,881,812 members
Articles / All Topics

Device Independent Units to Points to Inches

Rate me:
Please Sign up or sign in to vote.
4.67/5 (5 votes)
5 Nov 2009CPOL2 min read 38.8K   9   3
The default unit of measurement in Windows Forms was pixels. This worked well when most monitors on the market used a simple 96 pixel per inch measurement, but measuring by pixel causes problems when working with devices that have different resolutions.

The default unit of measurement in Windows Forms was pixels. This worked well when most monitors on the market used a simple 96 pixel per inch measurement, but measuring by pixel causes problems when working with devices that have different resolutions. For example, with Windows Forms, a 100 pixel button would appear to be about an inch wide on a 96 pixel/inch monitor. However, on a 120 pixel/inch monitor, the same button would appear to be 4/5 of an inch. A 160 pixel/inch monitor would show the button as 5/8 of an inch. And on a 60 pixel/inch screen, the button would appear to be about 1 2/3 inches wide.

With the introduction of WPF, Microsoft began using DIU (Device Independent Units). A DIU (also known as a Device Independent Pixel, or DIP) measurement is based on inches rather than hardware-specific pixels. A DIU is defined as 1/96 of an inch (smaller than the point, which is defined as 1/72 of an inch). For a standard 96 pixel per inch monitor, 96 DIU = 96 pixels. For monitors with 120 pixels/inch, 96 DIU = 120 pixels. For a monitor with 60 pixels/inch, 10 DIU = 60 pixels. When the measurement doesn't work out to a perfectly round number (as is often the case), WPF will automatically use anti-aliasing, or you have the option of “snapping” to the nearest pixel if you don't want "fuzzy" outlines for your button, etc.

One kink is that all measurements, including text, are now measured in DIU. In Windows Forms, depending on what control you were using, font size was often measured in points (a point is 1/72 of an inch and is the measurement used in Word and other applications). So now when you specify font size 12, you are actually specifying a 9 point font (which is probably smaller than you intended).

To help with this transition, I've put together a quick chart to quickly convert inches and points into DIU. I hope this helps:

Units of Measurement

Inches

Points

DIU

1/963/41
1/7211 1/3
1/481 1/22
1/322 1/43
1/2434
1/164 1/26
1/1268
1/8912
5/361013 1/3
1/61216
3/1613 1/218
1/41824
1/32432
1/23648
3/45472
17296
1 1/2108144
2144192
3216288
4288384
5360480
8576768
10720960
11 1/28281104
128641152

* 'Device-Independent Units' (DIU) are also called 'Device-Independent Pixels' (DIP)

View on

This article was originally posted at http://cyborgx37.blogspot.com/feeds/posts/default

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionvery helpful, a typo? Pin
jianyunli2-Apr-19 4:10
jianyunli2-Apr-19 4:10 
GeneralMy vote of 5 Pin
Rod Falanga4-Apr-13 11:01
Rod Falanga4-Apr-13 11:01 
GeneralMy vote of 4 Pin
Andru Martin21-Feb-11 21:28
Andru Martin21-Feb-11 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.