方法可以具有不同变量的输入/输出吗
方法是:
Robot robot = new Robot();
Color inputColor = new Color();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
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())
{
robot.mouseMove(x, y);
break;
}
}
}
return;
}
我想用 Color 值调用该方法,让它在屏幕截图中搜索该颜色,并返回像素的 (x, y) 值(如果找到),这种情况会发生吗?或者一个方法只能有一个输入和输出必须相同吗?
the method is:
Robot robot = new Robot();
Color inputColor = new Color();
Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
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())
{
robot.mouseMove(x, y);
break;
}
}
}
return;
}
i want to call that method with a value for Color have it search the screenshot for that color and return with the (x, y) values for the pixel if it is found can that happen or can a method have only one input and the output has to be the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以执行以下操作:
您也可以只返回两个元素
int[]
而不是一个点。You can do something like this:
You could also just return a two-element
int[]
instead of a point.方法输入和输出可能不同,但它不能返回多个类型(或)值,x 或 y。如果你想同时返回x,y。您可能需要作为数组返回(或者)您可以有一个类似于下面的 POJO 类,将 x,y 设置为该类的实例并返回。
Method input and output could be different, but it can't return more than one type(or)value, either x or y. If you want to return both x,y. You may need to return as array (or) You can have a POJO class something like below, set x,y to instance of that class and return.
您可以返回 java.awt.Point 与 x 和 y 值或使用
int
数组(如果可以的话)。You can return the java.awt.Point with the x and y values or use an
int
array if that would be fine.