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

java.awt.Robot.createScreenCapture() produces garbage on an invisible X server

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • P3
    • None
    • 6
    • client-libs
    • generic
    • generic

    Description

      When you create two X servers on Linux (which usually can be switched via Ctrl+Alt+F7 and F8), switch to one of them and run the following code against the other:

      import java.awt.Rectangle;
      import java.awt.Robot;
      import java.awt.Toolkit;
      import java.awt.image.BufferedImage;
      import java.io.OutputStream;
      import java.io.FileOutputStream;
      import java.io.BufferedOutputStream;
      import java.io.File;

      import javax.imageio.ImageIO;
      import javax.imageio.stream.FileImageOutputStream;
      import javax.imageio.stream.ImageOutputStream;
      import javax.imageio.ImageWriter;

      public class AWTBug {
              public static void main(String[] args) throws Exception {
                      Robot robot = new Robot();
                      BufferedImage src = robot.createScreenCapture(new Rectangle(0, 0, 100, 100));
                      ImageWriter iw = (ImageWriter) ImageIO.getImageWritersBySuffix("png").next();
                      ImageOutputStream os = new FileImageOutputStream(new File("image" + System.getenv("DISPLAY").replace(':', '_') + ".png"));
                      iw.setOutput(os);
                      iw.write(src);
                      iw.dispose();
                      os.close();
              }
      }

      ...the captured image contaings a lot of garbage (mostly black or random pixels).

      The bug seems to be in the capturing code, because when we capture images in a loop and compare them, most of them are different from each other.

      The same bug occurs on solaris-sparcv9, solaris-i586 and linux-i586 (haven't tried the other platforms).

      Attachments

        Activity

          People

            art Artem Ananiev (Inactive)
            kshiroko Kirill Shirokov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: