Java Image 获取桌面图像并创建宏
嗯,我正在玩在线 Flash 游戏,您必须尽快点击白色方框。我怎样才能用 Java 自动化这个过程呢?盒子的位置是随机的。
我尝试使用 Robot
类并使用 getPixelColor
,但这太慢了。
那么我需要做什么:
- 我的游戏窗口是 500x500 窗口,因此从中获取像素,
- 找到 5x5 白色框,
- 单击它们
有什么建议吗?
Well I'm playing a online flash game and you have to click on white boxes as fast as possible. How could I automate this with Java? The location of boxes is randomized.
I tried using Robot
class and use getPixelColor
, but that is way too slow.
So what I need to do:
- my game windows is 500x500 window, so get pixels from it
- find 5x5 white boxes
- click on them
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Rectangle 类,使用“包含”方法。
或者您可以创建自己的,其工作原理如下:
例如,如果屏幕上有两个框:
这将为您提供两个框,每个框其中 10x10 像素在尺寸上。 “boxA”的左上角位于 (0, 0),“boxB”的左上角位于 (20, 20)。
如果“mouseClicked”事件的 (x, y) 坐标是 (7, 7),则它在“boxA”的范围内(因为点 (7, 7) 位于 (0, 0) 和 (10, 10 )
如果“mouseClicked”事件的 (x, y) 坐标为 (23, 25),则它在“boxB”内,因为 (23, 25) 位于(20, 20) 和 (30, 30)
做的话,循环遍历框列表将会快得多。
你是对的, getPixelColor 对于你想要做的事情来说太慢了,如果你这样 想要深入研究更深入的示例,这里有一篇关于 碰撞检测。
You could use the Rectangle class, using the "contains" method.
Or you could create your own, which essentially works like this:
For example if you have two boxes on the screen:
This gives you two boxes, each of which is 10x10 pixels in size. "boxA" has it's top-left corner at (0, 0), and "boxB" has its top-left corner at (20, 20).
If the "mouseClicked" event's (x, y) coordinate is (7, 7), then that is within the bounds of "boxA" (because the point (7, 7) is between (0, 0) and (10, 10)
If the "mouseClicked" event's (x, y) coordinate is (23, 25), then it's within "boxB", because (23, 25) is between (20, 20) and (30, 30)
You're right that getPixelColor is too slow for what you're trying to do. Looping over the list of the boxes will be much faster.
If you want to dig into a much deeper example, here's an article on the concept of collision detection.