简体   繁体   中英

Robot.createScreenCapture is changing the colors

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM