在編碼圖集過程中,出現了Android IllegalArgumentException: Cannot draw recycled bitmaps錯誤。
大致意思是:不能使用已經被回收的bitmap。
bitmap回收部分代碼如下:
1 Bitmap removeBitmap = softReference.get(); 2 if(removeBitmap != null && !removeBitmap.isRecycled()){ 3 removeBitmap.recycle(); 4 removeBitmap = null; 5 }
解決方法:
重寫ImageView中的OnDraw方法,捕獲此異常。
1 public class MyImageView extends ImageView { 2
3 public MyImageView (Context context, AttributeSet attrs) { 4 super(context, attrs); 5 } 6
7 @Override 8 protected void onDraw(Canvas canvas) { 9 try { 10 super.onDraw(canvas); 11 } catch (Exception e) { 12 System.out.println("trying to use a recycled bitmap"); 13 } 14 }
