Java 如果/然后与像素查找和循环,所有这一切都在我之上的时刻
我想拍摄一个屏幕截图,如果像素是正确的RGB值,那么拍摄另一个屏幕截图并找到下一个像素,否则重复 这是获得像素的代码,它就像一个魅力Java 如果/然后与像素查找和循环,所有这一切都在我之上的时刻,java,Java,我想拍摄一个屏幕截图,如果像素是正确的RGB值,那么拍摄另一个屏幕截图并找到下一个像素,否则重复 这是获得像素的代码,它就像一个魅力 { BufferedImage image = robot.createScreenCapture(rectangle); search: for(int x = 0; x < rectangle.getWidth(); x++) { for(int y = 0; y < rectangle.getHeight(
{
BufferedImage image = robot.createScreenCapture(rectangle);
search: for(int x = 0; x < rectangle.getWidth(); x++)
{
for(int y = 0; y < rectangle.getHeight(); y++)
{
if(image.getRGB(x, y) == color3.getRGB())
{
break search;
}
}
}
}
好的,上下文,我正在构建一个程序,它经过几个步骤,一个打开给定的拼图,我把它放下,因为我可以使用简单的像素数据,然后它需要将鼠标放在中心像素上。问题是,我不能只使用第二个get pixel图像,因为游戏需要一段时间才能打开相关的jpanel,所以我需要我的程序等待,直到找到一个指示游戏已打开的像素,然后再开始寻找像素以使鼠标居中。您可能可以将屏幕截图代码分离成一个方法并调用它,直到您将获得所需的结果:
public boolean checkColor(Color inputColor) {
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++) {
for (int y = 0; y < rectangle.getHeight(); y++) {
if (image.getRGB(x, y) == inputColor.getRGB()) {
return true;
}
}
}
return false;
}
如果无法将屏幕截图与
newColor
匹配,此循环将终止。您可能可以将屏幕截图代码分离为一个方法并调用它,直到获得所需的结果:
public boolean checkColor(Color inputColor) {
BufferedImage image = robot.createScreenCapture(rectangle);
for(int x = 0; x < rectangle.getWidth(); x++) {
for (int y = 0; y < rectangle.getHeight(); y++) {
if (image.getRGB(x, y) == inputColor.getRGB()) {
return true;
}
}
}
return false;
}
如果无法将屏幕截图与
newColor
匹配,此循环将终止。请为您的操作提供上下文。请为您的操作提供上下文。
Color newColor = ...;
while (!checkColor(newColor)) {
new Color = new Color(114, 46, 33);
// Or change color in here for every iteration
}