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

L

lucy

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

Carl Howells

lucy said:
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.
 
J

Jacob

lucy said:
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;
 
L

lucy

Jacob said:
// 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
 
J

Jacob

lucy said:
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.
 
K

Keith Wansbrough

lucy said:
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:
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top