在编码图集过程中,出现了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     }  

 

相关文章:

  • 2021-05-15
  • 2021-12-06
  • 2021-11-04
  • 2022-01-08
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2022-12-23
  • 2021-04-08
  • 2021-11-11
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案