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步:点击白色 这就是我现在需要的帮助
答案 0 :(得分:1)
我真的不明白你的问题,但如果你在点击它(一次一个像素)时试图让白色变成阴影,那么你可以用它来使像素变暗: / p>
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;
}