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

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

1. ### lucyGuest

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...

lucy, Aug 2, 2004

2. ### Carl HowellsGuest

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...
>

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

3. ### JacobGuest

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
4. ### lucyGuest

"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
5. ### JacobGuest

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
6. ### Keith WansbroughGuest

"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

--KW
--
Keith Wansbrough <>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.

Keith Wansbrough, Aug 4, 2004