如何在Java中检测Retina显示器? [英] How do you detect a Retina Display in Java?
本文介绍了如何在Java中检测Retina显示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测用户在Java中是否具有视网膜显示?我已经知道使用 Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor")
来检测比例因子,但是Java不允许我将返回的值转换为int.我想知道如何将其转换为int或另一种检测视网膜显示的方法.
How can I detect if a user has a retina display in Java? I am already aware of detecting the scale factor using Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor")
, but java won't let me convert the returned value into an int. I'm wondering how I can convert that into an int, or another way to detect retina displays.
推荐答案
我将以这种方式获取值-
I would get the value this way -
public static boolean hasRetinaDisplay() {
Object obj = Toolkit.getDefaultToolkit()
.getDesktopProperty(
"apple.awt.contentScaleFactor");
if (obj instanceof Float) {
Float f = (Float) obj;
int scale = f.intValue();
return (scale == 2); // 1 indicates a regular mac display.
}
return false;
}
这篇关于如何在Java中检测Retina显示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文