Canvas: trying to use a recycled bitmap android.graphics.Bitmap in Android

后端 未结 8 1709
忘掉有多难
忘掉有多难 2020-12-13 17:32

I am working on the crop image class, but encounter a recycled bit map problem:

03-02 23:14:10.514: E/AndroidRuntime(16736): FATAL EXCEPTION: Thread-1470
03-         


        
8条回答
  •  执念已碎
    2020-12-13 17:45

    For those that did not find a solution so far. I had the same problem. I tried to recycle a bitmap in onPause like this:

    final Drawable drawable = mImageView.getDrawable();
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        bitmap.recycle();
    }
    
    if (preView != null && !preView.isRecycled()) {
        preView.recycle();
        preView = null;
    }
    

    After returning back i got the exception: "Canvas: trying to use a recycled bitmap"

    Solution for me: I had to add the following

    mImageView.setImageBitmap(null);
    

提交回复
热议问题