2017-04-19 62 views
0

我使用SubsamplingScaleImageView與滑翔加載,緩存和顯示圖片:滑翔:無法複製回收的位圖

SubsamplingScaleImageView mImageView; 

Glide.with(this) 
.load(url) 
.asBitmap() 
.into(new SimpleTarget<Bitmap>() { 
     @Override 
     public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { 
       mImageView.setImage(ImageSource.bitmap(
        Bitmap.createBitmap(resource, x1, y1, x2 - x1, y2 - y1))); 
     } 
    }); 

它的工作原理,但有時死機,錯誤IllegalStateException: Can't copy a recycled bitmapBitmap.createBitmap。如何解決它?

回答

0

出於某種原因,你的Bitmap得到回收。要修復它,您可以執行檢查,然後繼續進行必要的操作:

@Override 
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { 
    if (!resource.isRecycled()) { 
     mImageView.setImage(ImageSource.bitmap(Bitmap.createBitmap(resource, x1, y1, x2 - x1, y2 - y1))); 
    } 
} 
+0

但是,此檢查圖像將不會顯示。有另一種方式來實現呢? – BArtWell

+1

你必須找出原因是什麼/什麼條件下,/什麼樣的結果你'Bitmap'得到回收。在這個階段(在這個回調),我想不出比試圖重新加載圖像的任何其他。 – azizbekian