サーバーにサイズ 1000x800 の画像があります。次のアプローチを使用してダウンロードします。
完全な画像をダウンロードし、ピクセル値を配列に入れ、そこからビットマップをデコードしてスケーリングします。
image の一部をダウンロードし、それらをキャンバスに配置し、キャンバスをスケーリングします。
メモリの問題に関しては、どちらのアプローチが適していますか?
サーバーにサイズ 1000x800 の画像があります。次のアプローチを使用してダウンロードします。
完全な画像をダウンロードし、ピクセル値を配列に入れ、そこからビットマップをデコードしてスケーリングします。
image の一部をダウンロードし、それらをキャンバスに配置し、キャンバスをスケーリングします。
メモリの問題に関しては、どちらのアプローチが適していますか?
最良の方法は次のとおりです。
3) 画像をデコードせずにダウンサンプリング/スケーリングする
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
ここで 説明。サンプルコードもそこからです。