我正在 Linux 下使用 OpenJDK 11 使用 java.awt.Robot
创建屏幕截图。Linux 上的结果是全黑图像。相同的代码适用于 Ubuntu 和 Windows(当然使用另一个文件路径)。
有什么线索吗?
public void captureScreen() throws AWTException {
Robot robot = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
BufferedImage screen = robot.createScreenCapture(new Rectangle(getDefaultToolkit().getScreenSize()));
try {
ImageIO.write(screen, "jpg", new File("/tmp/screenshot.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
UPDATE: The the cause of the problem lies in the combination of OpenJDK and Wayland. With Oracle JDK/JRE (13.0.1) everything works fine.
最佳答案
如果您使用 wayland 而不是 XOrg,这可能会导致问题,因为它对于图形操作的 Java 接口(interface)不太稳定。
编辑:此错误现已修复(请参阅OP)
关于java - 截图机器人在 Debian 上仅捕获黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59008567/