Hey there, Im in need of a little help!
How would you go about searching for a certain color in a screenshot?
Many thanks
Hey there, Im in need of a little help!
How would you go about searching for a certain color in a screenshot?
Many thanks
First you need the color which you are searching and a color for what are you looking
Color mycolor= new Color(0,19,20) // R G B
Color screencolor = new Color(0,0,0);
Then you need the robot class
Robot robot = new Robot();
then you use the robot class to get the pixel color from a x,y position.
screencolor = robot.getPixelColor(arg0, arg1) // put x for arg0 and y for arg1 in
and then you have to check if these colors are equal
if(mycolor.equals(screencolor))
{
}
What if i don't know what the coords are? (Different Screen resolutions) How can i scan the image for a certain color?
Here is an code exempel of your question, hope it helpsCode:int R = 67; int G = 52; int B = 60; int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; int x = 0; int y = 0; Robot robot = new Robot(); BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); for (y = 0; y < screenHeight; y++) { for (x = 0; x < screenWidth; x++) { int clr = screenShot.getRGB(x,y); int red = (clr & 0x00ff0000) >> 16; int green = (clr & 0x0000ff00) >> 8; int blue = clr & 0x000000ff; if (red == R && green == G && blue == B) { robot.mouseMove(x, y); System.out.println("found it!"); y = screenHeight; x = screenWidth; } } }![]()
Last edited by rolingo; 01-18-2010 at 02:54 PM.
I believe there's way to get around it to read processor memory
but doing it in java is just simply harder and prabably not as efficient too.
But can it me done? I think the answer is positive
not many place talks about it thou.. simply it makes you look weird.