1

サーバーにサイズ 1000x800 の画像があります。次のアプローチを使用してダウンロードします。

  1. 完全な画像をダウンロードし、ピクセル値を配列に入れ、そこからビットマップをデコードしてスケーリングします。

  2. image の一部をダウンロードし、それらをキャンバスに配置し、キャンバスをスケーリングします。

メモリの問題に関しては、どちらのアプローチが適していますか?

4

1 に答える 1

1

最良の方法は次のとおりです。

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);
}

ここで 説明。サンプルコードもそこからです。

于 2012-06-23T09:22:25.477 に答える