![是否可以使用 Java 截取辅助 Windows 10 桌面的屏幕截图?](https://linux22.com/image/1585959/%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8%20Java%20%E6%88%AA%E5%8F%96%E8%BE%85%E5%8A%A9%20Windows%2010%20%E6%A1%8C%E9%9D%A2%E7%9A%84%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE%EF%BC%9F.png)
如果我想截取具有多个适配器/屏幕的扩展桌面的屏幕截图,我可以使用以下代码:
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 程序截取其他虚拟桌面的屏幕截图?
我尝试将宽度加倍Rectangle
(1920x2),但从像素 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);
}