Search code examples
javalinuxdebianopenjdk-11

Screenshot robot only captures a black screen on Debian


I am creating a screen capture using java.awt.Robot under Linux with OpenJDK 11. The result on Linux is a whole black image. The same code works on Ubuntu and Windows (using another file path of course).

Any clue?

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.


Solution

  • If you are using wayland instead of XOrg this may be causing the problem as it is less stable with Java interfaces for graphics operations.

    Edit: This bug has now been fixed (see OP)