java.lang.RuntimeException: Canvas:
trying to use a recycled bitmap android.graphics.Bitmap@3073cd5
at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:55)
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:226)
at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:529)
at android.view.View.getDrawableRenderNode(View.java:19377)
at android.view.View.drawBackground(View.java:19313)
at android.view.View.draw(View.java:19110)
at android.view.View.updateDisplayListIfDirty(View.java:18069)
at android.view.View.draw(View.java:18847)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18060)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4198)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4178)
at android.view.View.updateDisplayListIfDirty(View.java:18028)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4198)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4178)
at android.view.View.updateDisplayListIfDirty(View.java:18028)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4198)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4178)
at android.view.View.updateDisplayListIfDirty(View.java:18028)
at android.view.View.draw(View.java:18847)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18060)
at android.view.View.draw(View.java:18847)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18060)
at android.view.View.draw(View.java:18847)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18060)
at android.view.View.draw(View.java:18847)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18060)
at android.view.View.draw(View.java:18847)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.draw(View.java:19122)
at com.android.internal.policy.DecorView.draw(DecorView.java:785)
at android.view.View.updateDisplayListIfDirty(View.java:18069)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:643)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:649)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:757)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2980)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2794)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2347)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
08-13 06:44:54.834 21842-21842/com.picart.snapfilter.squareblur E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
一、参考
https://blog.csdn.net/primer_programer/article/details/26697037
https://blog.csdn.net/sex_34/article/details/47725707
以上两篇建议新建ImageView,重写onDraw()
报错: drawBitmap catch some exceptions
二、
https://blog.csdn.net/lchannel/article/details/75102028
这篇建议注释掉onDestroy
三、
https://blog.csdn.net/binbosmile1/article/details/50775926
这篇建议定位使用了已回收图片的地方,直接注释掉
这篇worked,but I didn't locate the error position sucessfully
我怎么找到的呢:找我最近改动的几个java文件,command+F:recycle,然后注释掉,运行一下,发现确实可以解决这个error。
但是还存在一个问题,我写的listview是很多张图片,在我点击图1,然后点击图2,……,然后点击图6,再返回点击图2时候,肉眼可以看见背景变化过程中有图1的缓存,虽然这个变化过程很快但是我看见了……
出错的在这里
public void recycleDrawable(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
Bitmap bmp = ((BitmapDrawable) drawable).getBitmap();
if (bmp != null && !bmp.isRecycled()) {
// bmp.recycle();//必须注释掉
bmp = null;
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@3073cd5 at android.g...
Android的Bitmap和J2ME的Image比较类似。 如果我想从resource里读入一个图片,然后在这个图片上draw一点自己的信息,比如文字。
再画到屏幕上怎么做呢?
J2ME里只要Image.getGraphic() 拿到 Graphic的对象就可以想draw什么就draw什么了。
那么Android里怎么实现呢?
Java 代码 代码如下: Bitmap img = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas();
canvas.s
< script src = "lib/Bitmap.js" > < / script >
< script >
var canvas = document . createElement ( "canvas" ) ;
var ctx = canvas . getContext ( "2d" ) ;
var imageData = ctx . getImageData ( 0 , 0 , canvas . width , canvas . height ) ;
var blob = Bitmap . createBlob ( imageData . data , canvas . width , canvas . height ) ;
var img = new Image ( ) ;
img . onload =
一开始分享的代码是这样的,可以分享给WeChat、QQ、短信。发现在分享完短信在退回界面后,原本的bitmap图片不见了。日志报错trying to use a recycled bitmap。bitmap被回收掉了
if(shareDialog == null) {
shareDialog = new ShareDialog();
BitmapDr...
异常:trying to use a recycled bitmap android.graphics.Bitmap
概意:试图使用已经recycled的Bitmap
一般情况下我们在对Bitmap进行Matrix的各种缩放、平移等处理,然后createBitmap,再对之前的Bitmap进行recycle处理。
Bitmap oldBitmap= BitmapFactory.d...
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@b66e6ff
at android.graphics.Canvas.throwI...
当你的应用由于加载大量图片出现OOM异常时,肯定会上网搜索关于OOM的文章,并导求相应的解决方案,比如压缩图片大小,或手动回收资源什么的。在这里我们不讨论图片压缩或缓冲这些方法,而是讨论一下手动回收
BITMAP时可能出现的问题,亦即
Canvas:
trying to
use a re
cycled
bitmap。
很容易可以预料到,你必然会遇到并使用如下代码:
Android UI开发(五)Bitmap和Canvas实例.docxAndroid UI开发(五)Bitmap和Canvas实例.docxAndroid UI开发(五)Bitmap和Canvas实例.docxAndroid UI开发(五)Bitmap和Canvas实例.docxAndroid UI开发(五)Bitmap和Canvas实例.docxAndroid UI开发(五)Bitmap和Canvas实例.docxAndroid UI开发(五)Bitmap和Canvas实例.docxAndroid UI开发(五)Bitmap和Canvas实例.docx
1.概念区别:
很多网友刚刚开始学习Android平台,对于Drawable、Bitmap、Canvas和Paint它们之间的概念不是很清楚,其实它们除了Drawable外早在Sun的J2ME中就已经出现了,但是在Android平台中,Bitmap、Canvas相关的都有所变化。
首先让我们理解下Android平台中的显示类是View,但是还提供了底层图形类android.graphics,今天所说的这些均为graphics底层图形接口。
Bitmap – 称作位图
一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565、RGB888。作为一种逐像素的显示对象执行效率高,但是缺
FATAL EXCEPTION: main
java.lang.RuntimeException:
Canvas:
trying to
use a re
cycled
bitmap android.
graphics.
Bitmap@41434a00
文章目录Glide使用背景使用方式一:into传入ImageView分析1:scaleType=fitXY是否会导致trying to use a recycled bitmap异常?分析2:into传入imageView是否会导致trying to use a recycled bitmap异常?使用方式二:into传入ViewTarget异常原因分析解决方案
Glide导致的RuntimeException: Canvas: trying to use a recycled bitmap android
Android 大图加载显示
文章目录
Android 大图加载显示通过本文你能学到什么?一、ImagerView直接放置一张几十M的图片会崩溃吗?二、如何保证加载大图不发生崩溃?三、Glide设置显示大图是否会发生崩溃四、大图缩放滑动如何实现五、大图缩放和滑动框架的使用六、最后总结一下最开始目录学习的内容:共勉:自强不息,才是生活的样子。
通过本文你能学到什么?
1、普通设置方法设置大图片是否会导致界面崩溃,多大的图片才会导致崩溃
2、如何保证加载大图不发生崩溃
3、Glide设置显示大图是否会发生崩溃
如何将Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo); Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(circleBitmap); Paint paint = new Paint(); paint.setAntiAlias(true); canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawBitmap(circleBitmap, 0, 0, null);返回的bitmap对象放入imageview
```java
Bitmap bitmap =
BitmapFactory.decodeResource(getResources(), R.drawable.logo);
Bitmap circle
Bitmap =
Bitmap.create
Bitmap(
bitmap.getWidth(),
bitmap.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new
Canvas(circle
Bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawCircle(
bitmap.getWidth() / 2,
bitmap.getHeight() / 2, Math.min(
bitmap.getWidth(),
bitmap.getHeight()) / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.draw
Bitmap(
bitmap, 0, 0, paint);
canvas.draw
Bitmap(circle
Bitmap, 0, 0, null);
ImageView imageView = findViewById(R.id.imageView);
imageView.setImage
Bitmap(circle
Bitmap);