Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 505
Reto Avatar asked Nov 23 '19 14:11

Reto


1 Answers

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)

like image 170
James Stone Avatar answered Sep 17 '22 14:09

James Stone