シンプルな単語ゲーム アプリで、次のコードを使用して、 PNG イメージ ストライプから 26 文字のタイル イメージを読み込みます。
private static final CharacterIterator ABC =
new StringCharacterIterator("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
private static HashMap<Character, Bitmap> sImages =
new HashMap<Character, Bitmap>();
BitmapRegionDecoder decoder = null;
InputStream is = sContext.getResources()
.openRawResource(R.drawable.big_english);
try {
decoder = BitmapRegionDecoder.newInstance(is, false);
} catch (IOException ex) {
}
int h = decoder.getHeight();
Rect r = new Rect(0, 0, h, h);
for (char c = ABC.first();
c != CharacterIterator.DONE;
c = ABC.next(), r.offset(h, 0)) {
Bitmap bmp = decoder.decodeRegion(r, null);
sImages.put(c, bmp);
}
これは Android エミュレーターでうまく機能します。
しかし、実際の Moto G デバイスでは、文字が大きすぎます (おそらく 1.5 倍?印刷するsContext.getResources().getDisplayMetrics().density
と、何らかの理由で 2.0 になります):
同時に、黄色の四角いタイルの背景が正しく表示されます。
すべて ( big_tile.pngとbig_english.pngとgame_board.png ) は PNG 画像です。なぜ違いがあるのでしょうか?
なぜそれが起こるのか、これを修正する方法を教えてください。
inDensity
または他のBitmapFactory.Optionsを使用する必要がありますか?
それとも私のgetResources().openRawResource()
電話のせいですか - しかし、代わりに何を使うべきですか?