how to map from display metrics to physical metrics...

Discussion in 'Java' started by lucy, Aug 2, 2004.

  1. lucy

    lucy Guest

    Suppose I have a screen which is 1024x768, how can I map this rectangle in
    pixels into physical world dimensions in meters or in inches? Actually I
    want to know the physical size of the viewable area of the monitor...

    Please help me...
    lucy, Aug 2, 2004
    #1
    1. Advertising

  2. lucy

    Carl Howells Guest

    lucy wrote:
    > Suppose I have a screen which is 1024x768, how can I map this rectangle in
    > pixels into physical world dimensions in meters or in inches? Actually I
    > want to know the physical size of the viewable area of the monitor...
    >
    > Please help me...


    First, please don't crosspost to so many groups. clj.machine is
    completely inappropriate for this topic.

    Second, that problem is unsolvable without actually *asking* the user
    what size their display is. Many monitors can't be queried about their
    size, and there's nothing you can do to change that.
    Carl Howells, Aug 2, 2004
    #2
    1. Advertising

  3. lucy

    Jacob Guest

    lucy wrote:

    > Suppose I have a screen which is 1024x768, how can I map this rectangle in
    > pixels into physical world dimensions in meters or in inches? Actually I
    > want to know the physical size of the viewable area of the monitor...


    // Pixel size of screen
    Dimension pixelSize = Toolkit.getDefaultToolkit().getScreenSize();

    // Screen resolution (for some reason returned as inches, please fix Sun!)
    int pixelsPerInch = Toolkit.getDefaultToolkit().getScreenResolution();
    double pixelsPerMeter = pixelsPerInch / 0.0254;

    // Compute width and heigth of screen in meters
    double screenWidth = pixelSize.width / pixelsPerMeter;
    double screenHeight = pixelSize.height / pixelsPerMeter;
    Jacob, Aug 2, 2004
    #3
  4. lucy

    lucy Guest

    "Jacob" <> wrote in message
    news:...
    > lucy wrote:
    >
    > > Suppose I have a screen which is 1024x768, how can I map this rectangle

    in
    > > pixels into physical world dimensions in meters or in inches? Actually I
    > > want to know the physical size of the viewable area of the monitor...

    >
    > // Pixel size of screen
    > Dimension pixelSize = Toolkit.getDefaultToolkit().getScreenSize();
    >
    > // Screen resolution (for some reason returned as inches, please fix Sun!)
    > int pixelsPerInch = Toolkit.getDefaultToolkit().getScreenResolution();
    > double pixelsPerMeter = pixelsPerInch / 0.0254;
    >
    > // Compute width and heigth of screen in meters
    > double screenWidth = pixelSize.width / pixelsPerMeter;
    > double screenHeight = pixelSize.height / pixelsPerMeter;
    >


    Hi Jacob,

    Thank you very much for answer. I have tried that
    Toolkit.getDefaultToolkit().getScreenResolution();

    No matter how I set my resolution: 1024x768, 1600x1200, it always gives back
    120 dpi. Then 1024/120= 8 inches, 768/120=6 inches, then the diagonal size
    will be 10 inches, but actually I am using a 20 inch monitor...

    so that's the problem, Java does not know how to get the actual physical
    viewable size of the monitor:

    I found in VC++, it has the following:

    hSize=GetDeviceCaps(hScreenDC,HORZSIZE);
    vSize=GetDeviceCaps(hScreenDC,VERTSIZE);

    gives back the correct values in "cm",

    but I really want to get the values in Java, for cross platform
    compatibility...

    Any more thoughts?

    Thanks a lot,

    -Lucy
    lucy, Aug 2, 2004
    #4
  5. lucy

    Jacob Guest

    lucy wrote:

    > No matter how I set my resolution: 1024x768, 1600x1200, it always gives back
    > 120 dpi.


    It whould be interesting to know where/how Java picks up this
    information. On a Windows machine it might be of no surprise
    that VB makes a better job figuring these measures.

    I'm on a Linux PC, and have run the code I posted, and still
    get it about 15% wrong (as measured with a ruler). I haven't
    switched resolution though.
    Jacob, Aug 2, 2004
    #5
  6. "lucy" <> writes:

    > Suppose I have a screen which is 1024x768, how can I map this rectangle in
    > pixels into physical world dimensions in meters or in inches? Actually I
    > want to know the physical size of the viewable area of the monitor...


    Google "EDID". Anything you do will be very platform-specific,
    though, and will likely involve your program interacting with an
    external EDID-reading utility.

    --KW :cool:
    --
    Keith Wansbrough <>
    http://www.cl.cam.ac.uk/users/kw217/
    University of Cambridge Computer Laboratory.
    Keith Wansbrough, Aug 4, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew

    VHDL Code Metrics

    Andrew, Jun 7, 2005, in forum: VHDL
    Replies:
    6
    Views:
    939
    Nicolas Matringe
    Jun 9, 2005
  2. =?Utf-8?B?Ukc=?=

    Session State Performance Metrics

    =?Utf-8?B?Ukc=?=, Jan 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    405
    Saravana
    Jan 7, 2005
  3. Ed Dana
    Replies:
    3
    Views:
    335
    Steve W. Jackson
    Feb 11, 2005
  4. Edward Berard

    Java Source Code Metrics Tools

    Edward Berard, Mar 9, 2005, in forum: Java
    Replies:
    4
    Views:
    9,307
    satwindercse
    Aug 2, 2010
  5. Phlip
    Replies:
    1
    Views:
    516
Loading...

Share This Page