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