color=bitmap.getPixel(x,y)
を使用して、指定された位置のColor整数を取得します。次に、[0..255]の範囲の各色の値を表すColorクラスのred(color)
,green(color)
およびblue(color)
のメソッドを使用します。
アルファチャンネルに関しては、他のすべての色に比率を掛けることができます。ここで
は実装例です:
int width = bitmap.getWidth();
int height = bitmap.getHeight();
ByteBuffer b = ByteBuffer.allocate(width*height*3);
for (int y=0;y<height;y++)
for (int x=0;x<width;x++) {
int index = (y*width + x)*3;
int color = bitmap.getPixel(x,y);
float alpha = (float) Color.alpha(color)/255;
b.put(index, (byte) round(alpha*Color.red(color)));
b.put(index+1, (byte) round(alpha*Color.green(color)));
b.put(index+2, (byte) round(alpha*Color.blue(color)));
}
byte[] pixelArray = b.array();