Android IllegalArgumentException: Cannot draw recycled bitmaps解決方法


在編碼圖集過程中,出現了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     }  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM