2

Here's the class I wrote to take screenshots:

public class imagemanipulation {

    Dimension screenResolution;
    Rectangle screenRectangle;
    Robot robot;

    imagemanipulation() {
        try {
            screenResolution = Toolkit.getDefaultToolkit().getScreenSize();
            screenRectangle = new Rectangle(screenResolution);
            robot = new Robot();
        } catch (AWTException ex) {
            Logger.getLogger(imagemanipulation.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public BufferedImage newScreenshot() {
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        return image;
    }

}

What I am doing is using BufferedImagewhatever.getRGB(x,y) on both a screenshot of the screen taken from the above, and coordinates of it to part of another image, then returning the x and y position where a match is found. This works great for black and white images but not colored. The problem I'm having is that createScreenCapture is changing the RGB colors of the screenshot from what they were originally, so when I compare an image taken with createScreenCapture to another image it never works.

I think createScreenCapture must be reducing the amount of colors in the screenshots it takes as to be more efficient, but is there any way I can stop it from doing that?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
David Zorychta
  • 13,039
  • 6
  • 45
  • 81
  • *"changing the RGB colors of the screenshot from what they were originally"* What do you mean by 'originally'? What software produces the original image? If it is also the `Robot`, one might guess that whatever optimizations it may (or may not) be performing, would be constant across different invocations. I have previously written software that will successfully detect 'a region that has changed' (e.g. a GUI appearing on one) between two screenshots done with the `Robot`. – Andrew Thompson Dec 17 '11 at 02:41
  • Essentially, my problem is that any image captured by the robot seems to be losing its correct colour values. The colours in images taken using robot are ever so slightly distorted from what they should be, so I cannot use it to compare to other images due to this discolouration. I'm not sure why robot is doing this. – David Zorychta Dec 17 '11 at 03:46
  • In that slew of words, I do not see an answer to **What software produces the original image?** – Andrew Thompson Dec 17 '11 at 04:01
  • Post your SSCCE that demonstrates your problem. – camickr Dec 17 '11 at 04:15

1 Answers1

1

For reference, this example allows one to click and drag to a point on the desktop, displaying an enlarged image of the surrounding screen. Once captured, the color is displayed in a tool tip as the mouse moves over the captured image. I have verified that the result is correct using a utility on my platform. You might compare it to your program and result.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045