0

私の問題についてもっと言及しました。しかし、私はまだ問題を解決できず、特定のデバイス、特に Galaxy S3 で問題が発生する理由を予測できません。他のデバイスでも同じアプリを実行していますが、問題なく動作しています。Eclipse MAT を使用してメモリ リークを発見しました。それはまさに私のアプリで使用されている私の画像編集クラスにあります。アプリケーション全体でこれを使用したため、bitmap.recyle() は試していません。ImageEditView クラスは、画像を画面に表示するためのものです。以下のスニペットを使用してビットマップをロードしました。

private Bitmap decodeAndDownsampleImageURI(Uri uri) {
    Bitmap bitmap = null;

    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inPurgeable = true; 

        BufferedInputStream in = new BufferedInputStream(getContext().getContentResolver().openInputStream(uri));
        BitmapFactory.decodeStream(in, null, options);
        in.close();

        int scale = 1;
        if (options.outHeight > IMAGE_MAX_SIZE || options.outWidth > IMAGE_MAX_SIZE) {
            scale = (int) Math.pow(
                    2,
                    (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(options.outHeight, options.outWidth))
                                        / Math.log(0.5)));
        }

        options = new BitmapFactory.Options();
        options.inSampleSize = scale;
        in = new BufferedInputStream(getContext().getContentResolver().openInputStream(uri));
        bitmap = BitmapFactory.decodeStream(in, null, options);
        in.close();
    } catch (FileNotFoundException e) {
        log.error(MyStyleApplication.hockeyAppLogMessage, e);
        Log.e(TAG, "decodeAndDownsampleImageUri()", e);
    } catch (Exception e) {
        log.error(MyStyleApplication.hockeyAppLogMessage, e);
        Log.e(TAG, "decodeAndDownsampleImageUri()", e);
    }

    return bitmap;
}

}

誰でも私の問題を解決するためのより良い解決策を提案してください。

4

2 に答える 2

1

以下のコードを使用できます。それはあなたの問題を解決します

BitmapFactory.Options options = new BitmapFactory.Options();
                                options.inSampleSize = 4;
 in = new BufferedInputStream(getContext().getContentResolver().openInputStream(uri));
    bitmap = BitmapFactory.decodeStream(in, null, options);

それでも問題が解決しない場合は、画像を縮小できます。

Bitmap newBmp=Bitmap.createScaledBitmap(bitmap , 100, 100, true);
于 2013-10-14T09:03:42.437 に答える