回收再利用后的位图变位图、再利用

2023-09-06 13:08:39 作者:心安勿忘

我已经回收了位图的变量,当我试图再次使用相同的变量,我有一些奇怪的错误,参照回收。任何解决这个问题?

的Java code:

image1.recycle(); 此搜索= NULL;

LogCat中:

  11月五号至29日:35:42.139:E / AndroidRuntime(695):java.lang.RuntimeException的:画布:试图用一个循环位图android.graphics.Bitmap@2bbad018
十一月5号至29号:35:42.139:E / AndroidRuntime(695):在android.graphics.Canvas.throwIfRecycled(Canvas.java:1038)
十一月5号至29号:35:42.139:E / AndroidRuntime(695):在android.graphics.Canvas.drawBitmap(Canvas.java:1078)
 

解决方案

在你回收的内存被释放的位图。这是否意味着位图数据从内存中消失了。如果你想再次使用相同的变量,你必须去$ C C的位图againg $。

 如果(此搜索== NULL || image1.isRecycled()){
    此搜索= BitmapFactory.de codeStream()
}
 
动力电池逐渐进入生命末期 回收和再利用变得愈发重要

I have recycled the bitmap variable and when I again tried to use the same variable I have some strange errors with reference to recycle. Any solution to this issue ?

java code:

image1.recycle(); image1=null;

LogCat:

05-29 11:35:42.139: E/AndroidRuntime(695): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@2bbad018
05-29 11:35:42.139: E/AndroidRuntime(695):  at android.graphics.Canvas.throwIfRecycled(Canvas.java:1038)
05-29 11:35:42.139: E/AndroidRuntime(695):  at android.graphics.Canvas.drawBitmap(Canvas.java:1078)

解决方案

Once you recycle the bitmap its memory is freed. That's mean that bitmaps data are gone from the memory. If you want to use again the same variable you have to decode the Bitmap againg .

if (image1 == null || image1.isRecycled()) {
    image1 = BitmapFactory.decodeStream()
}

 
精彩推荐
图片推荐