简体   繁体   中英

How to get correct DPI of display with Java, when user change the screen resolution on Windows settings?

To be able get dpi value, I am using this:

float dpi = Toolkit.getDefaultToolkit().getScreenResolution();

In advance display settings, When I applied 1366 x 768 as a resolution value;

dpi value returns 96 (That is what I expected)

However, When I changed 800 x 600 as a resolution value in settings;

dpi value returns 96 (That should be lower value than 96 )

When I try same case in mac computer, the right values are coming.

I think there is something wrong in the resolution value which comes from Windows OS. I have tested for Windows 7 and Windows 10 .

Edit : To understand why I need this value, check this question and its answer .

I think the answer is in official documentation :

Specifies what size to show text and other items on the screen. Windows DPI value is an integer between 96 and 480. Supported values include 96, 120, and 144. By default, Windows uses automatic DPI configuration.

Thats why It returns 96 for 800 x 600.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM