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?