且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android IllegalArgumentException: Cannot draw recycled bitmaps解决方法

更新时间:2022-08-12 17:12:40

在编码图集过程中,出现了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方法,捕获此异常。

Android IllegalArgumentException: Cannot draw recycled bitmaps解决方法
 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     }  
Android IllegalArgumentException: Cannot draw recycled bitmaps解决方法

 

---------------------------------------------------------------------------------
笔者水平有限,若有错漏,欢迎指正,如果转载以及CV操作,请务必注明出处,谢谢!

本文转自Windstep博客园博客,原文链接:http://www.cnblogs.com/lwbqqyumidi/p/3407626.html,如需转载请自行联系原作者