実はとても簡単です!
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);
Bitmapオブジェクトができたら、いくつかのオプションがあります。
bm.getPixel(x,y)またはなど、クラス内のにint対応するを返します。intColorColor.BLACKColor.WHITE
さらに、bm.copyPixelsToBuffer(Buffer destination)すべてのピクセルをオブジェクトにコピーしBufferます。オブジェクトは、ピクセルごとに検索できます。
詳細については、ドキュメントを確認してください。
ビットマップドキュメント
カラードキュメント
/ res /drawableフォルダーに「image」という画像があると仮定した場合のコードのサンプルスニペットを次に示します。
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);
int pixelColor = bm.getPixel(10,10); //Get the pixel at coordinates 10,10
if(pixelColor == Color.BLACK) {
//The pixel is black
}
else if(pixelColor == Color.WHITE) {
//The pixel was white
}
明らかに、ピクセルの取得には注意する必要があります。ピクセルが存在し、座標が画像より大きくないことを確認してください。の寸法を取得するには、それぞれBitmapとを使用bm.getHeight()しbm.getWidth()ます。