屏幕截图机器人仅捕获 Debian 上的黑屏

Screenshot robot only captures a black screen on Debian

我正在使用 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 图形操作接口时不太稳定。

编辑:此错误现已修复(参见 OP)