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

Robot.createScreenCapture() does not work on VirtualBox with installed GuestAdditions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Other
    • Icon: P4 P4
    • None
    • 9
    • client-libs
    • None

      Steps to reproduce:

      - Install Ubuntu 14.04 on VirtualBox
      - Install VirtualBox Guest Additions
      - Install JDK 9
      - Run the program:
      ---------------------------
      import java.io.File;
      import javax.imageio.ImageIO;
      import java.awt.Dimension;
      import java.awt.Rectangle;
      import java.awt.Robot;
      import java.awt.Toolkit;
      import java.awt.image.BufferedImage;

      public class ScreenCaptureTest {

          public static void main(String[] args) throws Exception {

              if (args.length < 1) {
                  throw new RuntimeException("Image save path is not specified!");
              }

              Robot robot = new Robot();
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              BufferedImage image = robot.createScreenCapture(new Rectangle(screenSize));
              ImageIO.write(image, "png", new File(args[0], "screenshot.png"));
          }
      }
      ---------------------------

      The saved image is either black or only desktop background is saved.

            alexsch Alexandr Scherbatiy
            alexsch Alexandr Scherbatiy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: