我正在尝试使用Java获取屏幕监视器分辨率。问题是我没有得到正确的输出。三个显示器中的第一个显示的像素宽度为5760而不是1920.它们都具有相同的尺寸1920x1080。
代码:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
System.out.println("Number of devices: " + gs.length);
System.out.println("Default resolution: " + java.awt.Toolkit.getDefaultToolkit().getScreenSize());
for (int i = 0; i < gs.length; i++) {
System.out.printf("id: %s, width: %d, height: %d\r\n", gs[i].getIDstring(), gs[i].getDisplayMode().getWidth(), gs[i].getDisplayMode().getHeight());
}
输出:
Number of devices: 3
Default resolution: java.awt.Dimension[width=5760,height=1080]
id: :0.0, width: 5760, height: 1080
id: :0.1, width: 1920, height: 1080
id: :0.2, width: 1920, height: 1080
有关如何获得所有三种正确的显示器像素大小的任何提示?
编辑1:
xrandr
的输出是:
myuser@mysystem ~ $ xrandr
Screen 0: minimum 8 x 8, current 5760 x 1080, maximum 32767 x 32767
DVI-D-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 connected 1920x1080+3840+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+ 59.94 50.00 60.05 60.00 50.04
1680x1050 59.95
1440x900 59.89
1280x1024 75.02 60.02
1280x960 60.00
1280x800 59.81
1280x720 60.00 59.94 50.00
1152x864 75.00
1024x768 75.03 70.07 60.00
800x600 75.00 72.19 60.32 56.25
720x576 50.00
720x480 59.94
640x480 75.00 72.81 59.94 59.93
DP-0 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+ 59.94 50.00 60.05 60.00 50.04
1680x1050 59.95
1440x900 59.89
1280x1024 75.02 60.02
1280x960 60.00
1280x800 59.81
1280x720 60.00 59.94 50.00
1152x864 75.00
1024x768 75.03 70.07 60.00
800x600 75.00 72.19 60.32 56.25
720x576 50.00
720x480 59.94
640x480 75.00 72.81 59.94 59.93
HDMI-2 connected primary 1920x1080+1920+0 (normal left inverted right x axis y axis) 531mm x 299mm
1920x1080 60.00*+ 59.94 50.00 60.05 60.00 50.04
1680x1050 59.95
1440x900 59.89
1280x1024 75.02 60.02
1280x960 60.00
1280x800 59.81
1280x720 60.00 59.94 50.00
1152x864 75.00
1024x768 75.03 70.07 60.00
800x600 75.00 72.19 60.32 56.25
720x576 50.00
720x480 59.94
640x480 75.00 72.81 59.94 59.93