gpt4 book ai didi

Linux 上的 Java : getDisplayMode() fails in multi screen

转载 作者:太空宇宙 更新时间:2023-11-04 04:08:13 25 4
gpt4 key购买 nike

我有一个桌面java应用程序(java 1.4.2),需要确定Linux环境下两个屏幕的信息:

# cat /etc/redhat-release
Red Hat Enterprise Linux WS release 4 (Nahant Update 7)
# lsb_release
cat /proc/versionLSB Version:
:core-3.0-ia32:core-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch
# cat /proc/version
Linux version 2.6.9-78.ELsmp (brewbuilder@hs20-bc2-3.build.redhat.com)
(gcc version 3.4.6 20060404 (Red Hat 3.4.6-10)) #1 SMP Wed Jul 9 15:39:47 EDT 2008

屏幕分辨率为 2048x2048 和 1600x1200。

代码是

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] allScreens = env.getScreenDevices();
log("=============================================");
log("Total num. of screen = " + allScreens.length);
for (int i = 0; i < allScreens.length; i++) {
log("--------------------------------------");

log(
allScreens[i].getIDstring() + " width: " + allScreens[i].getDisplayMode().getWidth() +
" - height: " + allScreens[i].getDisplayMode().getHeight());

GraphicsConfiguration dgc =
allScreens[i].getDefaultConfiguration();
Rectangle bounds = dgc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(dgc);
log("Bounds: " + bounds);
log("Insets: " + insets);

log("--------------------------------------");
}
log("=============================================");

但是输出是

=============================================
Total num. of screen = 2
--------------------------------------
:0.0 width: 2048 - height: 2048
Bounds: java.awt.Rectangle[x=0,y=0,width=2048,height=2048]
Insets: java.awt.Insets[top=0,left=0,bottom=0,right=0]
--------------------------------------
--------------------------------------
:0.1 width: 2048 - height: 2048
Bounds: java.awt.Rectangle[x=0,y=0,width=1600,height=1200]
Insets: java.awt.Insets[top=0,left=0,bottom=0,right=0]
--------------------------------------
=============================================

屏幕:0.1在使用allScreens[i].getDisplayMode()时为2048x2048,在使用getDefaultConfiguration().getBounds()时为1600x1200:

为什么我有不同的结果?

getDisplayMode()的API代码是

public DisplayMode getDisplayMode() {
GraphicsConfiguration gc = getDefaultConfiguration();
Rectangle r = gc.getBounds();
ColorModel cm = gc.getColorModel();
return new DisplayMode(r.width, r.height, cm.getPixelSize(), 0);
}

所以值应该是相同的:为什么不同?

谢谢

最佳答案

我在自己的应用程序中也注意到了这一点,该应用程序需要前端 GUI 才能适应多显示器环境中的不同显示器。问题与显卡有关,如果您使用 allScreens[i].getDisplayMode(),Intel 显卡将为您提供不同显示器(基本上是主显示器)相同的宽度和高度,而 NVidia 和 ATI(AMD) 显卡会使用相同的函数为您提供与每个显示器相对应的实际分辨率值。

因此,无论显卡如何,在多显示器环境中为每个显示器获取正确的分辨率的正确方法是使用 getDefaultConfiguration().getBounds().width 或 height。

希望有帮助。

关于Linux 上的 Java : getDisplayMode() fails in multi screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20281023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com