0

我正在寻找一种更好、更“深入”的方法来扫描我的屏幕以获取某些图像。就我而言,我正在自动化在线流程,而我目前用于扫描屏幕并寻找“盒子”的方法是这样的

private boolean boxChecker() {
    Robot iris = null;
    data.boxFound = false;
    try{
        iris = new Robot();
    }catch (Exception e){}

    System.out.println("flash");
    BufferedImage TestShot = iris.createScreenCapture(new Rectangle(0,0,width,height));

    // finding points
    boolean FoundPoint = false;
    int FirstX = 0;
    int FirstY = 0;        
    int tempx = (int)width/2 ;
    int tempy = 60;
    tan = 0;
    grey = TestShot.getRGB(tempx, tempy);
    black = 0; 
    System.out.println("before i start, tempx is "+tempx+" and tempy is "+tempy);
    try{

    do{
        int colour = TestShot.getRGB(tempx, tempy);
        if (colour != grey ){ // this is the first point here!!
            System.out.println("the first point is at "+tempx+" by "+tempy);
            tan = colour;
            FirstX = tempx;
            FirstY = tempy;
            FoundPoint = true;
        }
        else{
            tempy++;
        }

    } while(!FoundPoint);

    FoundPoint = false;
    do{
        int colour = TestShot.getRGB(tempx, tempy);

        if (colour == grey ){ // this is the second point here!!
            tempx++;
            System.out.println("the second point is at "+tempx+" by "+tempy);
            FoundPoint = true;

        }
        else{
            tempx--;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{ // this is for the third point
        int colour = TestShot.getRGB(tempx, tempy);
        if (colour != tan ){ // this is the third point here!!
            black = colour;
            System.out.println("the third point is at "+tempx+" by "+tempy);
            FoundPoint = true;
        }
        else{
            tempy++;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{
        int colour = TestShot.getRGB(tempx, tempy);

        if (colour == grey ){ // this is the fourth point here!!
            tempx--;
            System.out.println("the fourth point is at "+tempx+" by "+tempy);
            FoundPoint = true;

        }
        else{
            tempx++;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{
        int colour = TestShot.getRGB(tempx, tempy);
        if (colour == grey ){ // this is the fifth point here!!
            tempy++;
            System.out.println("the fifth point is at "+tempx+" by "+tempy);
            FoundPoint = true;
        }
        else{
            tempy--;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{
        if (FirstX == tempx && FirstY == tempy ){ // this is the sixth point here!!
            System.out.println("the sixth point is at "+tempx+" by "+tempy);
            FoundPoint = true;
        }
        else{
            tempx--;
        }
    } while(!FoundPoint);

    data.boxFound = true;
    return true;
    } catch (Exception e){
        System.err.println("wrong screen bro");
        data.boxFound = false;
        return false;
    }
}

现在我知道这是一种可怕的方法,因为它依赖于屏幕和一切,但这就是为什么我需要一种更好的方法。

请注意,这确实适用于我的程序。

4

0 回答 0