UIに少数の画像を適用しようとしましたが、setImageResource
を使用するスペースがないため、bitmap
を使用しました。 問題は割り当てに失敗したことを示します。ビットマップを使用して割り当てに失敗しました -
java.lang.OutOfMemoryError: Failed to allocate a 93600012 byte allocation with 16765312 free bytes and 70MB until OOM
この問題を解決するお手伝いができれば幸いです。
int imgResource = item.getIcon(); // for example imgResource = R.drawable.test
Drawable drawable = context.getResources().getDrawable(imgResource); //Here I get the error
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
holder.iv.setImageBitmap(bitmap);
ありがとう!
画像がどのくらいあるの? (幅x高さ) –
これは、https://developer.android.com/topic/performance/graphics/load-bitmap.htmlに役立ちます – Pavan
@SteveSmithこのコードは機能の一部であり、関数は25個の画像とすべての画像を取得します異なります。 – japi99