[英]how to look for a colour and click on it (white colour keeps changing shades) Java
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import java.awt.Color;
public class main {
private static Robot robot = null;
public static void main(String[] args)
{
try {
robot = new Robot ();
} catch (AWTException e) {
e.printStackTrace();
}
klick (700 , 118);
robot.delay(5000);
colour(700,118);
}
public static void klick ( int x , int y)
{
robot.mouseMove(x, y);
robot.delay(5);
robot.mousePress(MouseEvent.BUTTON1_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_MASK);
}
public static void colour (int x, int y)
{
robot.delay(5);
Color color = robot.getPixelColor(x,y);
robot.delay(5);
System.out.println("Red = " + color.getRed());
System.out.println("Green = " + color.getGreen());
System.out.println("Blue = " + color.getBlue());
}
}
我希望它在屏幕上的任何地方都能找到白色,然后单击它,这就是我到目前为止所拥有的。 步骤1:单击固定点步骤2:查找白颜色步骤3:单击白颜色这就是我现在需要的所有帮助
我不太了解您的问题,但是如果您要使白色在单击时变成白色(一次像素),则可以使用它使像素变暗:
public BufferedImage shadePixel(BufferedImage img, int x, int y, int darkness){
//x is the mouse x position & y is the mouse y position
Color color = new Color(img.getRGB(x, y));
int imgR = color.getRed()-darkness;//if it makes it brighter try + instead of -
int imgG = color.getGreen()-darkness;
int imgB = color.getBlue()-darkness;
Color color2 = new Color(imgR, imgG, imgB);
img.setRGB(x, y, color2.getRGB());
return img;
}
希望能帮助到你 :)
但是,如果要让它检测不同的阴影,则可以尝试以下操作:
public boolean isShadeOfWhite(BufferedImage img, int x, int y){
Color color = new Color(img.getRGB(x, y));
int imgR = color.getRed();
int imgG = color.getGreen();
int imgB = color.getBlue();
if(imgR == imgG && imgR == imgB){
return true;
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.