pkwithpink
Apprentice

- Joined
- Nov 14, 2008
- Sythe Gold
- 0
- Messages
- 770
Hi I need help on how to search for a certain RGB color on screen and getting the coordinates of that color. Any help would be appreciated.

/**
* @param colour The colour to search for in the image.
* @param area The area to search for the colour, a portion of the stored currentArea.
* @return Returns the point in reference to the stored currentArea image if found, or
* (-1,-1) if not found.
*/
public static Point FindColour(Color colour, Rectangle area) {
int[] rgb = new int[area.width*area.height];
currentArea.getRGB(area.x, area.y, area.width, area.height, rgb, 0, area.width);
Point found = new Point(-1,-1);
int searchColour = colour.getRGB();
for(int i = 0; i < rgb.length; i++) {
if(rgb[i] == searchColour) {
int y = i / currentArea.getWidth();
int x = i - (y*currentArea.getWidth());
found = new Point(x + area.x,y + area.y);
return found;
}
}
return new Point(-1,-1);
}

