方法可以具有不同变量的输入/输出吗

发布于 2025-01-04 09:19:15 字数 607 浏览 2 评论 0原文

方法是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晨与橙与城 2025-01-11 09:19:15

您可以执行以下操作:

Point methodName(Color color) {
    Point p = new Point();
    // logic for finding point
    return p; // or perhaps return null if color not found
}

您也可以只返回两个元素 int[] 而不是一个点。

You can do something like this:

Point methodName(Color color) {
    Point p = new Point();
    // logic for finding point
    return p; // or perhaps return null if color not found
}

You could also just return a two-element int[] instead of a point.

地狱即天堂 2025-01-11 09:19:15

方法输入和输出可能不同,但它不能返回多个类型(或)值,x 或 y。如果你想同时返回x,y。您可能需要作为数组返回(或者)您可以有一个类似于下面的 POJO 类,将 x,y 设置为该类的实例并返回。

Dimension
{
int x;
int y;

setter..
getter..
}

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.

Dimension
{
int x;
int y;

setter..
getter..
}
陌上青苔 2025-01-11 09:19:15

You can return the java.awt.Point with the x and y values or use an int array if that would be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文