问题
I'm using java to get the dimensions and resolution of my screen. When I run the following code, I get the output below.
Toolkit toolkit = Toolkit.getDefaultToolkit ();
Dimension dim = toolkit.getScreenSize();
System.out.println("Width of Screen Size is "+dim.width+" pixels");
System.out.println("Height of Screen Size is "+dim.height+" pixels");
int resolution =Toolkit.getDefaultToolkit().getScreenResolution();
System.out.println(resolution);
output:
Width of Screen Size is 1920 pixels
Height of Screen Size is 1080 pixels
120
Now the Javadoc says that getScreenResolution returns the resolution in dpi (dots per inch). I take that to mean if I have an image that is 600pxs wide that it would be 5 inches on my screen. When I measure, it is actually 4 inches wide. Indicating to me that it should be 150 dpi.
My monitor is a 15.6" monitor and I measure it to be 13.6" wide and a little more than 7.6" tall. Now the width of my screen is apparently 1920 pixels wide which calculates to about 141 pixels per inch. Similarly 1080/7.6 calculates to about 141 pixels per inch.
This web page displays a 600x600px image. I measure it on my screen to be 4.25" which calculates to 141 pixels.
Why does getScreenResolution return 120?
Please let me know if I am mistaken on any of this.
回答1:
Toolkit.getDefaultToolkit().getScreenResolution()
tries to get the resolution, but depending how accurate the drivers are and other thing (like that not all connections between the video card and monitor are not capable of feedback about the sizes), the size returned cannot be fully thrusted.
来源:https://stackoverflow.com/questions/15334392/java-toolkit-screen-resolution-descrepensies