
如果我想截取具有多個適配器/螢幕的擴展桌面的螢幕截圖,我可以使用以下程式碼:
static void takeScreenShot(String path) throws AWTException, IOException {
Rectangle screenRect = new Rectangle(0, 0, 0, 0);
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
screenRect = screenRect.union(gd.getDefaultConfiguration().getBounds());
}
BufferedImage capture = new Robot().createScreenCapture(screenRect);
File output = new File(path);
ImageIO.write(capture, "bmp", output);
}
但是,就我而言,我只有 1 個 VGA 適配器(板載)、1 個顯示器 (HDMI),而且我正在使用新的 Windows 10 虛擬桌面功能。
如何使用類似的 Java 程式截取另一個虛擬桌面的螢幕截圖?
我嘗試將 (1920x2) 的寬度加倍Rectangle
,但從像素 1920 到 3840,截取的螢幕截圖上全是黑色。
static void takeScreenShot(String path) throws AWTException, IOException {
Rectangle screenRect = new Rectangle(0, 0, 1920*2, 1080);
BufferedImage capture = new Robot().createScreenCapture(screenRect);
File output = new File(path);
ImageIO.write(capture, "bmp", output);
}