Java中的快速像素搜索 [英] Fast Pixel Search in Java

查看:126
本文介绍了Java中的快速像素搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对java中的像素搜索有疑问。
目前,我的Class / Programm逐像素搜索,以减缓我的目的。
我想用Java来搜索像素的速度要快得多,所以我开始想问你们。
我正在用RGB颜色搜索像素。这是我的源代码:

i have a problem regarding a pixel search in java. At the moment my Class/Programm is searching pixel by pixel thats to slow for my purposes. I wan't Java to search the Pixels much faster so i came to the idea to ask you guys. I'm searching for the pixels by an RGB color. This is my Source code:

    final int rot = 0;
    final int gruen = 0;
    final int blau = 0;
    int toleranz = 1;

    Color pixelFarbe;

    Dimension bildschirm = Toolkit.getDefaultToolkit().getScreenSize();


    Robot roboter = null;
    try {
        roboter = new Robot();
    } catch (AWTException e) {
        e.printStackTrace();
        OrbitRaider.log("Robot is not working.");
    }

    for(int x = 0; x <= bildschirm.getWidth(); x++)
    {
        for(int y = 0; y <= bildschirm.getHeight(); y++)
        {
            // Pixelfarbe bekommen
            pixelFarbe = roboter.getPixelColor(x, y);

            // Wenn Pixelfarbe gleich unserer Farbe
            if( (pixelFarbe.getRed() < (rot - toleranz)) || (pixelFarbe.getRed() > (rot + toleranz))
                && (pixelFarbe.getGreen() < (gruen - toleranz)) || (pixelFarbe.getGreen() > (gruen + toleranz)) 
                && (pixelFarbe.getBlue() < (blau - toleranz)) || (pixelFarbe.getBlue() > (blau + toleranz)) ){("Could not find Pixel Color");

            }

            else{
                System.out.println("Pixelcolor found at x: " + x + " y: " + y);
            }
        }
    }


推荐答案

使用 createScreenCapture 方法,然后检查这个BufferedImage的像素 - 不是用明显的getRGB方法(这也是因为颜色很慢)每次调用时发生的空间转换),但是通过BufferedImage后面的int数组。

Probably it is much faster to create a screen capture with the createScreenCapture method of the Robot class, and then inspect the pixels of this BufferedImage - not with the obvious getRGB method (this is also quite slow because of the color space conversions that occur on each call), but going through the int array which is behind the BufferedImage.

请参阅: Java - 从图像中获取像素数组

这篇关于Java中的快速像素搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆