how to map from display metrics to physical metrics...  
Author Message
lucy





PostPosted: 2004-8-3 2:07:00 Top

java-programmer, how to map from display metrics to physical metrics... 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...


 
Carl Howells





PostPosted: 2004-8-3 3:07:00 Top

java-programmer >> how to map from display metrics to physical metrics... 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.
 
Jacob





PostPosted: 2004-8-3 3:51:00 Top

java-programmer >> how to map from display metrics to physical metrics... 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;

 
 
lucy





PostPosted: 2004-8-3 3:53:00 Top

java-programmer >> how to map from display metrics to physical metrics...
"Jacob" <email***@***.com> wrote in message
news:email***@***.com...
> 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


 
 
Jacob





PostPosted: 2004-8-3 4:36:00 Top

java-programmer >> how to map from display metrics to physical metrics... 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.

 
 
Keith Wansbrough





PostPosted: 2004-8-4 7:24:00 Top

java-programmer >> how to map from display metrics to physical metrics... "lucy" <email***@***.com> 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 8-)
--
Keith Wansbrough <email***@***.com>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.