Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8246305

Robot screencapture fails on Wayland

XMLWordPrintable

    • x86
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      For example Debian 10 using Wayland. Any Java version is affected.

      A DESCRIPTION OF THE PROBLEM :
      Taking a screenshot or otherwise capture the content of a screen does not work with Wayland - only a plain black screen is captured.

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a screen capture using java.awt.Robot.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An image of the captured screen.
      ACTUAL -
      A plain black image.

      ---------- BEGIN SOURCE ----------
      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();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None. A Wayland developer commented the following:
      This is not a Wayland bug, this is a problem with java.awt.Robot. Report it to the proper place. Let them know that they can take screenshots with dbus or with wlr-screencopy, depending on the wayland compositor in question.

      FREQUENCY : always


            pardesha Pardeep Sharma
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: