【问题标题】:Scan screen for color扫描屏幕的颜色
【发布时间】:2011-03-03 06:55:45
【问题描述】:

我想在 Java 中扫描屏幕以查找特定颜色。

知道怎么做吗?

【问题讨论】:

  • 你需要这个做什么?只是好奇。
  • 是这样想的。这是我曾经玩过的游戏中最早使用的方法之一。可以将纹理交换为具有纯色的纹理,并且外部程序将扫描屏幕。当有人找到一种直接在内存中访问变量的方法时,它就已经过时了。

标签: java image-processing pixel screen-capture scanning


【解决方案1】:
    Robot robot = new Robot();
    Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage bufferedImage = robot.createScreenCapture(captureSize);
    // ...

    int color = image.getRGB(x, y);

    int  red = (color & 0x00ff0000) >> 16;
    int  green = (color & 0x0000ff00) >> 8;
    int  blue = color & 0x000000ff;
    // ...

【讨论】:

  • @Reuben Mallaby 剪切和粘贴的乐趣。颜色,您正在从颜色中找到 r g 和 b 值。我更新了我的帖子
  • @Thorbjørn Ravn Andersen - 修复机器人
  • Romain, "why" 指的是你吞下了异常而不是执行e.printStackTrace()
【解决方案2】:

使用 Java.awt.Robot 将屏幕截图作为图像并进行处理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 2017-07-12
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    相关资源
    最近更新 更多