Code:
public static Point pixelSearchArea(String hexColor, Point topLeft, Point bottomRight) throws AWTException{
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
int areaWidth = bottomRight.y - topLeft.y;
int areaHeight = bottomRight.y - topLeft.y;
Rectangle area = new Rectangle(topLeft.x, topLeft.y, areaWidth, areaHeight);
Color colorColor = Color.decode(hexColor);
int searchColor = colorColor.getRGB();
Robot r = new Robot();
Rectangle screenRect = area;
BufferedImage bimage = r.createScreenCapture(screenRect);
int width = bimage.getWidth();
int height = bimage.getHeight();
int[] colors = new int[width * height];
int[] all = bimage.getRGB(0, 0, width, height, colors , 0, width);
for(int i = 0; i < all.length; i++)
{
if (all[i] == searchColor)
{
int y = ((i + 1) / width);
int x = (i) - (y * width);
return new Point(screenWidth - (screenWidth - topLeft.x) + x,screenHeight - (screenHeight - topLeft.y) + y);
}
}
return null;
}






