1

AndroidのビットマップサイズがVMの予算を超えています。

私のアプリはこのエラーを頻繁に受け取ります。2つの質問があります。

  1. aboutアクティビティをリサイクルする必要がありますか(いくつかのimageviewsとボタンとtextViewsが含まれています)?
  2. .recycle();との違いは何system.gc();ですか?
4

3 に答える 3

2

このビデオを見てみてください(romainguy):

http://www.youtube.com/watch?v=duefsFTJXzc&list=PLD1B287286E23E2D1&index=1&feature=plpp_video

これにより、ビットマップのベストプラクティスに関する洞察が得られます。

于 2012-08-13T16:51:34.220 に答える
2

あなたは常にrecycleそれらを使用した後にビットマップを試してみるべきです。

私が理解している限り、を呼び出さないようにしてくださいsystem.gc()。を呼び出すrecycle()と、ビットマップオブジェクトをガベージコレクションできます。

これがお役に立てば幸いです。

于 2012-08-13T16:53:31.740 に答える
0

カメラから画像を選択しているときに同じ問題が発生しました。
次のコードを使用して、画像のビットマップのサイズを変更しました。

Bitmap bitmap = resizeBitMapImage(picturePath, 75, 91);
            profilePic.setImageBitmap(bitmap);

private Bitmap resizeBitMapImage(String filePath, int targetWidth,
        int targetHeight) {

    Bitmap bitMapImage = null;
    // First, get the dimensions of the image
    Options options = new Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, options);
    double sampleSize = 0;
    // Only scale if we need to
    // (16384 buffer for img processing)
    Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
            .abs(options.outWidth - targetWidth);

    if (options.outHeight * options.outWidth * 2 >= 1638) {
        // Load, scaling to smallest power of 2 that'll get it <= desired
        // dimensions
        sampleSize = scaleByHeight ? options.outHeight / targetHeight
                : options.outWidth / targetWidth;
        sampleSize = (int) Math.pow(2d,
                Math.floor(Math.log(sampleSize) / Math.log(2d)));
    }

    // Do the actual decoding
    options.inJustDecodeBounds = false;
    options.inTempStorage = new byte[128];
    while (true) {
        try {
            options.inSampleSize = (int) sampleSize;
            bitMapImage = BitmapFactory.decodeFile(filePath, options);

            break;
        } catch (Exception ex) {
            try {
                sampleSize = sampleSize * 2;
            } catch (Exception ex1) {

            }
        }
    }
     return bitMapImage;
}
于 2013-05-29T11:03:28.020 に答える