我有一个关于java中的像素搜索的问题。目前,我的课程/程序正在逐个像素地搜索,这对于我的目的来说会变慢。我不想让 Java 更快地搜索像素,所以我想到了问你们的想法。我正在通过 RGB 颜色搜索像素。这是我的源代码:
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);
}
}
}