0

私は次のコードを持っています...

BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.test, options);
int[] pixels = new int[1];
if(b != null){
  pixels = new int[b.getHeight()*b.getWidth()];
  b.getPixels(pixels, 0, b.getWidth(), 0, 0, b.getWidth(), b.getHeight());
  for(int i = 0 ; i < 100 ; i++){
    Log.d("test","Pixel is :"+pixels[i]);
  }
}

R.drawable.test は res/drawable-nodpi ディレクトリにある .bmp ファイルです

しかし、0〜255の値の代わりに、このように見えると思います...

06-03 21:49:24.364: D/test(4088): Pixel is :-16777088
06-03 21:49:24.364: D/test(4088): Pixel is :-16777088
06-03 21:49:24.364: D/test(4088): Pixel is :-16777088
06-03 21:49:24.364: D/test(4088): Pixel is :-16777088
06-03 21:49:24.364: D/test(4088): Pixel is :-16777088
06-03 21:49:24.364: D/test(4088): Pixel is :-16777088
06-03 21:49:24.374: D/test(4088): Pixel is :-16777088

その番号はまったく正しくないようです。誰かが私が欠けているものを手伝ってくれますか?

4

1 に答える 1

3

ピクセルを RGB に変換する必要があります

ここにコードサンプルがあります

             int[] pix = new int[picw * pich];
             bitmap.getPixels(pix, 0, picw, 0, 0, picw, pich);

             int R, G, B, Y;

             for (int y = 0; y < pich; y++) {

                 for (int x = 0; x < picw; x++)
                     {
                     int index = y * picw + x;
                     int R = (pix[index] >> 16) & 0xff;     //bitwise shifting
                     int G = (pix[index] >> 8) & 0xff;
                     int B = pix[index] & 0xff;

                     //R, G, B - Red, Green, Blue
                     //to restore the values after RGB modification, use 
                     //next statement

                     pix[index] = 0xff000000 | (R << 16) | (G << 8) | B;

                    }
            }
于 2013-06-03T21:59:05.800 に答える