2017-09-19 9 views
0

私は、私の描画可能xhdpiフォルダ内の大きさで、その32×32ピクセルのイメージをPNG形式があります。Androidのビットマップの色の混乱

enter image description here 私は正確に2つの色を使用した画像を作成したとき。

renderSystem.addSprite(R.drawable.walltest, 0, 2); 

rendersystemにおいて:

public void addSprite(int id, int x, int y) { 
    Bitmap image = BitmapFactory.decodeResource(context.getResources(), id); 
    printColors(image); 
    //active.add(new Sprite(image, worldToScreenX(x), worldToScreenY(y))); 
} 


private void printColors(Bitmap src) { 
    for (int i = 0; i < src.getWidth(); i++) { 
     for (int j = 0; j < src.getHeight(); j ++) { 
      Log.d("Color", String.valueOf(src.getPixel(i,j))); 
     } 
    } 
} 

iは、ビットマップなどの画像をロードループトラフそれを、私はつ以上の異なる色値を参照logcatの各色値を印刷

出力:

09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 36 lines 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -7975603 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -10734540 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -11325392 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -7975603 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 8 lines 
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -7975603 
09-19 13:03:38.851 2576-2576/com.example.benjamin.dungeondweller D/Color: -10734540 
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 9 lines 
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller D/Color: -10734540 
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller D/Color: -12639196 
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216 
09-19 13:03:38.860 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 41 lines 
09-19 13:03:38.860 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216 

これは、ビットマップイメージに同じ色がないことを示していますソースPNG画像として使用します。何故ですか?そして、正確なレプリカをビットマップ形式で読み込むにはどうすればよいですか?

答えて

0

作成中にビットマップがフィルタされたためです。ピクセルの個々のRGB値をチェックし、そこに少しの違いを見てください。

+0

フィルタリングを無効にするにはどうすればよいですか? –

+0

私はビットマップファクトリオプションを作成し、inscaledをtrueに設定しました。今それは動作します。 –

+0

申し分なく、あなたのために良い。 –