Glide加载图片出现java.lang.IllegalStateException: Can't call reconfigure() on a recycled bitmap
来源:互联网 发布:php外卖系统源码 编辑:程序博客网 时间:2024/05/21 14:44
- Glide简介
- Glide用法
- gradle依赖
- 代码片段
- ProGuard混淆规则
- 兼容性
- Cant call reconfigure on a recycled bitmap
- 问题原因
- 典型代码
- 解决方法
Glide简介
Glide是面向Android的快速高效的开源媒体管理和图像加载框架,提供媒体解码,内存和磁盘缓存以及资源池等简单易用的用户体验。
Glide用法
gradle依赖
repositories { mavenCentral() // jcenter() works as well because it pulls from Maven Central}dependencies { compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.android.support:support-v4:19.1.0'}
代码片段
// For a simple view:@Override public void onCreate(Bundle savedInstanceState) { ... ImageView imageView = (ImageView) findViewById(R.id.my_image_view); Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);}// For a simple image list:@Override public View getView(int position, View recycled, ViewGroup container) { final ImageView myImageView; if (recycled == null) { myImageView = (ImageView) inflater.inflate(R.layout.my_image_view, container, false); } else { myImageView = (ImageView) recycled; } String url = myUrls.get(position); Glide .with(myFragment) .load(url) .centerCrop() .placeholder(R.drawable.loading_spinner) .crossFade() .into(myImageView); return myImageView;}
ProGuard混淆规则
-keep public class * implements com.bumptech.glide.module.GlideModule-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { **[] $VALUES; public *;}# for DexGuard only-keepresourcexmlelements manifest/application/meta-data@value=GlideModule
兼容性
Glide详细的兼容性问题可查看Github仓库,这里只列举一个:
- 圆角图片
CircleImageView/CircularImageView/RoundedImageView 与TransitionDrawable (.crossFade() 配合 .thumbnail() 或 .placeholder()使用时) 和 animated GIFs配合使用时会出现已知的问题,解决方法是使用BitmapTransformation (.circleCrop() 在v4版本才支持) 或者 .dontAnimate()。
Can’t call reconfigure() on a recycled bitmap
问题原因
This error usually means that the bitmap pool is tainted, so if you’re using Transformations anywhere in the app, that could be a culprit. Someone is recycling Bitmaps that are in the pool, outside of Glide’s knowledge.
Transformations anywhere in the app could be a culprit.
App中任何地方出现的Transformations可能就是罪魁祸首,Transformation就是配合Glide实现圆角图片的API。
典型代码
public class BitmapFixedWidthTransform extends BitmapTransformation { public BitmapFixedWidthTransform(Context context) { super(context); } @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { int targetWidth = outWidth; double aspectRatio = (double) toTransform.getHeight() / (double) toTransform.getWidth(); int targetHeight = (int) (targetWidth * aspectRatio); Bitmap result = Bitmap.createScaledBitmap(toTransform, targetWidth, targetHeight, true); if (result != toTransform) { // Same bitmap is returned if sizes are the same toTransform.recycle(); // removed this } return result; } @Override public String getId() { return "transformation" + " desiredWidth"; }}
解决方法
解决方法其实已经在上面的代码注释中,既然是由recycled bitmap引起的,那么去掉下面的代码就OK:
toTransform.recycle(); // removed this
- Glide加载图片出现java.lang.IllegalStateException: Can't call reconfigure() on a recycled bitmap
- Can't compress a recycled bitmap
- Can't compress a recycled bitmap的解决方案
- Glide异常:java.lang.IllegaliArgumentException:You must not call setTag() on a view Glide is targeting
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap
- java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting
- java.lang.IllegalArgumentException: You must not call setTag() on a view Glide is targeting
- Glide加载图片遇到的错误:You must not call setTag() on a view Glide is targeting
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41a7f048
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@412d7230
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap...
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@412d723
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@358df999
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap:报错解决
- xfire webservice异常 java.lang.IllegalStateException: Can't overwrite cause
- java.lang.IllegalStateException: Can't change tag of fragment
- java.lang.IllegalStateException: Can't change tag of fragment xxxFragment
- Glide 图片加载 java.lang.IllegalArgumentException
- Hadoop HBase入门学习
- Hadoop HBase操作数据学习
- Hadoop hbase-site.xml 参数收藏学习
- Android应用效果
- Hadoop HBase集群搭建
- Glide加载图片出现java.lang.IllegalStateException: Can't call reconfigure() on a recycled bitmap
- Hadoop HBase存储原理结构学习
- Python字符串类型的内建函数
- PHP-CGI 进程 CPU 100% 与 file_get_contents 函数的关系
- Hadoop MapReduce WordCount程序编写
- Hadoop MapReduce统计手机流量案例学习(结合Partitioner)
- RN实战项目页面导航和启动页面实现(三)
- 关于memchache的一点个人总结
- Hadoop MapReduce常见问题学习(shuffle)