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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Other
    • Affects Version/s: 9
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: