locked
Are "Device Independent Units" Just Hype? RRS feed

  • Question

  •  

     

    I'm trying to figure out the appeal of device independent units. I was actually excited when I first read about them. Since each unit is supposed to represent 1/96th of an inch, I figured that a 96 unit line would always equal one inch regardless of resolution, etc. Experimentation proves that this clearly isn't the case.

     

    Then I ran across this insightful post:

     

    http://www.wpflearningexperience.com/?p=41

     

    ...which seems to indicate that device independent units (DIUs) only work as advertised when:

     

    1) The user is running his monitor at native resolution, which is typically the maximum resolution.

     

    ** AND **

     

    2) The DPI setting, set to 96 by default in Vista, is manually set by the user to reflect the true DPI of the monitor.

     

    Since neither condition (much less both!) holds true for most users out there, "device independence" doesn't seem realistic in the vast majority of cases.

     

    I'm very new to WPF so I'm quite open to the possibility that I misinterpreted the article. Could someone comment DIUs? What's the real advantage of expressing everything in DIUs instead of physical pixels?

     

    Jules

    Thursday, February 7, 2008 12:36 AM

Answers

  • Drawing on the screen in units of pixels is a bad idea, particularly if you want your programs to run well on high-resolution monitors of the future.  What you draw in units of pixels may look fine on your display, but be much too tiny on somebody else's more expensive monitor.

     

    Traditionally, if you're writing a Windows program and you've wanted to draw in units of pixels, you obtain information from the system to help you do this in an intelligent manner.  For example, you get the height of the system font, or you get the assumed DPI of the video display.

     

    Windows has always provided the option for programs to draw on the screen in units of inches.  For example, Word can display a ruler on the screen.  If you hold an actual ruler up to the screen, will the two rulers be the same?  Not very likely, and for good reason:

     

    For desktop machines, most often the screen is further from the user's eye than, say, a book might be.  For notebook computers, the screen might actually be closer to the user's eye than a book.  For a projection system, the screen can be some 10, 20, or 30 feet away.  For these reasons, you don't want on-screen inches to always match real-world inches.  For desktop screens, you want on-screen inches to be a little larger; for notebooks, probably a bit smaller; and for projection screens, probably quite a bit larger.

     

    A Windows user should adjust the virtual screen resolution to a size where 9-point type is comfortably readable.  For many users and systems, that's the default 96 DPI.  For older users, it's often 120 DPI.  For high-resolution video displays of the future, it could be 144 DPI or maybe 300 DPI.

     

    What WPF gives you is a coordinate system that is usable with no further preparation.  You want to draw a 1-inch square box?  Use 96 units for the side.  On the printer, the box will be exactly 1-inch square.  On the screen, it probably won't be.  But the square will be able to fit 8 rows of a 9-point font -- and you as a programmer know that this text will be readable by the user.

     

    The WPF device-independent unit doesn't give you anything more than what Windows has always given you, except that it's more convenient.  To draw in units of inches with the WIndows API, you deliberately had to set a mapping mode.  In WinForms, you had to set the PageScale and PageUnits properties of the WinForms Graphics object.  In WPF, you  just go.

    Thursday, February 7, 2008 1:42 AM

All replies

  • Thursday, February 7, 2008 1:25 AM
  • IMO, I think people misunderstand device independant pixels.   They think, "hey this will look the same at all resolutions." You CAN design your layout so it does accomplish this very easy in WPF, but that is not automatic.

    Device independant pixels, to me means, I can set an image to be 50x50.  Say its container is a Viewbox.  If I make the viewbox 200x200, my Image will still have a width/height of 50x50 DIU, but rendered inside the viewbox, it may actually have 200x200 real-world pixels.  So instead using pixels, where pixel sizes change based on resolution of their display, you use device independant units which are dependant on your layout/rendering.

    Think of DIU in the same terms you would think of vector art, like in Illustrator.  Do you think vector graphics are described in pixels?

    -Jer
    • Proposed as answer by Adel K Monday, August 8, 2011 12:57 AM
    Thursday, February 7, 2008 1:36 AM
  • Drawing on the screen in units of pixels is a bad idea, particularly if you want your programs to run well on high-resolution monitors of the future.  What you draw in units of pixels may look fine on your display, but be much too tiny on somebody else's more expensive monitor.

     

    Traditionally, if you're writing a Windows program and you've wanted to draw in units of pixels, you obtain information from the system to help you do this in an intelligent manner.  For example, you get the height of the system font, or you get the assumed DPI of the video display.

     

    Windows has always provided the option for programs to draw on the screen in units of inches.  For example, Word can display a ruler on the screen.  If you hold an actual ruler up to the screen, will the two rulers be the same?  Not very likely, and for good reason:

     

    For desktop machines, most often the screen is further from the user's eye than, say, a book might be.  For notebook computers, the screen might actually be closer to the user's eye than a book.  For a projection system, the screen can be some 10, 20, or 30 feet away.  For these reasons, you don't want on-screen inches to always match real-world inches.  For desktop screens, you want on-screen inches to be a little larger; for notebooks, probably a bit smaller; and for projection screens, probably quite a bit larger.

     

    A Windows user should adjust the virtual screen resolution to a size where 9-point type is comfortably readable.  For many users and systems, that's the default 96 DPI.  For older users, it's often 120 DPI.  For high-resolution video displays of the future, it could be 144 DPI or maybe 300 DPI.

     

    What WPF gives you is a coordinate system that is usable with no further preparation.  You want to draw a 1-inch square box?  Use 96 units for the side.  On the printer, the box will be exactly 1-inch square.  On the screen, it probably won't be.  But the square will be able to fit 8 rows of a 9-point font -- and you as a programmer know that this text will be readable by the user.

     

    The WPF device-independent unit doesn't give you anything more than what Windows has always given you, except that it's more convenient.  To draw in units of inches with the WIndows API, you deliberately had to set a mapping mode.  In WinForms, you had to set the PageScale and PageUnits properties of the WinForms Graphics object.  In WPF, you  just go.

    Thursday, February 7, 2008 1:42 AM