少し問題がありました。すべてのピクセルを読み取り、ピクセルのRGBカラーを取得するコードを取得しました。しかしその前に、私は画像をチャンクにカットしたので、メモリを超えずに、より大きな画像を計算することもできます。コードは次のとおりです。
Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
try {
decoder_image = BitmapRegionDecoder.newInstance(filePath,
false);
} catch (IOException e) {
e.printStackTrace();
}
try {
boolean bool_pixel = true;
final int width = decoder_image.getWidth();
final int height = decoder_image.getHeight();
// Divide the bitmap into 1100x1100 sized chunks and process it.
// This makes sure that the app will not be "overloaded"
int wSteps = (int) Math.ceil(width / 1100.0);
int hSteps = (int) Math.ceil(height / 1100.0);
Rect rect = new Rect();
for (int h = 0; h < hSteps; h++) {
for (int w = 0; w < wSteps; w++) {
int w2 = Math.min(width, (w + 1) * 1100);
int h2 = Math.min(height, (h + 1) * 1100);
rect.set(w * 1100, h * 1100, w2, h2);
bitmap_image = decoder_image.decodeRegion(rect,
null);
try {
int bWidth = bitmap_image.getWidth();
int bHeight = bitmap_image.getHeight();
int[] pixels = new int[bWidth * bHeight];
bitmap_image.getPixels(pixels, 0, bWidth, 0, 0,
bWidth, bHeight);
for (int y = 0; y < bHeight; y++) {
for (int x = 0; x < bWidth; x++) {
int index = y * bWidth + x;
int R = (pixels[index] >> 16) & 0xff; //bitwise shifting
int G = (pixels[index] >> 8) & 0xff;
int B = pixels[index] & 0xff;
total++;
if (R == 255){
//Save x,y position
}
if ((G > (R+2)) && (G > (B+2))) {
counter++;
}
}
}
} finally {
bitmap_image.recycle();
}
}
}
} finally {
decoder_image.recycle();
}
これは魅力のように機能します。インターネットからいくつかの情報を持っていて、私はこれを自分のコード用に作り直しました。
しかし、私が今欲しいのは、つまり、彼が「完全な」赤いピクセル(255)を検出したとき、彼はそのピクセルのx、y位置を示さなければならないということです。
これは非常に簡単だと思いましたが、画像をチャックにカットしたため、非常に奇妙なx、y位置になりました(私が思うに)。
なぜこれが必要なのかを簡単に説明します。画像では、これらは2つの赤いピクセルであり、これら2つは長方形に変換する必要がありますが、x、yの位置が適切ではありません。
したがって、質問を明確にするために、赤いピクセルのx、y位置を取得するにはどうすればよいですか。
とても簡単かもしれませんが、どういうわけか私は正しい場所を取得できず、近くにさえありません。Photoshopで画像を開いてこれを確認し、赤いピクセルのx、yが何であるかを確認しますが、私のアプリは非常に奇妙な座標を提供します。
さらに詳しい情報などが必要な場合は、コメントしてください。
すでにありがとう、Bigflow