2013-06-03 3 views
0

에서 문제점에는 getPixels 나는 다음과 같은 코드가 ...안드로이드 : 비트 맵

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는 고해상도/당김-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 

그 숫자를 잘 전혀 보이지 않는 누군가가 내가 놓친 거지 무엇을 도와 수 있습니까?

답변

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; 

        } 
      } 
+0

무엇 PNG 및 추가 알파에 대한, 즉 – Jackie

+0

이 변화 http://stackoverflow.com/questions을한다/4845646/java-using-png-files-in-java-using-pixel-rgb-values-0-to-1 여기에 언급 된 내용 – varun