I'm looking for a better and "deeper" method of scanning my screen for certain images. In my case I am automating online processes and the current method I have for scanning my screen and looking for the "box" is this
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;
}
}
Now I know this is a horrible way of doing this because it is dependant on the screen and everything but thats why I need a better way of doing it.
Just as a note, this does work for my program as it is.