画像があり、ロボットと getPixelColor() を使用して特定のピクセルの色を取得する方法を見つけました。画像は私が制御しているキャラクターであり、ロボットに画像を絶えずスキャンさせて、周囲のピクセルが特定の色に等しいかどうかを教えてもらいたいです。これはまったく可能ですか?ありがとう!
1 に答える
1
私自身、ロボットを使用して「キャラクター」より少し大きい画像を抽出し、取得した BufferedImage を分析します。コースの詳細は、プログラムの詳細によって異なります。おそらく最も速いのは、BufferedImage の Raster を取得し、次にその dataBuffer を取得し、次にそのデータを取得し、返された配列を分析することです。
例えば、
// screenRect is a Rectangle the contains your "character"
// + however many images around your character that you desire
BufferedImage img = robot.createScreenCapture(screenRect);
int[] imgData = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
// now that you've got the image ints, you can analyze them as you wish.
// All I've done below is get rid of the alpha value and display the ints.
for (int i = 0; i < screenRect.height; i++) {
for (int j = 0; j < screenRect.width; j++) {
int index = i * screenRect.width + j;
int imgValue = imgData[index] & 0xffffff;
System.out.printf("%06x ", imgValue );
}
System.out.println();
}
于 2012-09-30T01:39:08.183 に答える