dimanche 12 mai 2019

Stopping script once color is no longer found in BufferedImage Java

I currently have a script that takes a screencap of an area and searches that area for every color value. However, I want the script to stop running once a specific color is not found in any area of the image. My current script stops the moment that a pixel is not the correct color, which is not what I want.

import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    public static void main(String args[]) throws AWTException {
        int i = 0;
        while (i < 1){
        BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
        BufferedImage image2 = new Robot().createScreenCapture(new Rectangle(70, 102,200,222));
\        for (int y = 0; y < image2.getHeight(); y++) {
            for (int x = 0; x < image2.getWidth(); x++) {
                Color pixcolor = new Color(image2.getRGB(x, y));
                int red = pixcolor.getRed();
                int green = pixcolor.getGreen();
                int blue = pixcolor.getBlue();
                System.out.println("Red  = " + red);
                System.out.println("Green  = " + green);
                System.out.println("Blue  = " + blue);

                if (red == 253 && green == 222 && blue == 131){
                            continue;
                        }
                        else {
                            System.out.println(x);
                            System.out.println(y);
                            i ++;
                            System.exit(1);;
                        }

    }
}}}}

Aucun commentaire:

Enregistrer un commentaire