2013-11-27 104 views
0
ImageView iv; 
Drawable d = imageView.getDrawable(); 
if (d instanceof BitmapDrawable) { 
    if (d is not resources) // How to check ??? iv.setImageResources(resId); 
     ((BitmapDrawable) d).getBitmap().recycle(); 
} 

我想除了回收繪圖資源位圖的繪製...如何知道是否從位圖圖像視圖或資源

回答

1

您不能檢查這樣的...但這種方法可以幫助你..

private void setImage(Drawable drawable,boolean isFromResource) { 
     imageView.setImageDrawable(drawable); 
     imageView.setTag(isFromResource); 
    } 

    private void recycle() { 
     Object object = imageView.getTag(); 
     if(object != null && object instanceof Boolean) { 
      boolean isFromResource = (Boolean) object; 
      if(!isFromResource) { 
       Drawable drawable = imageView.getDrawable(); 
       if(drawable != null && drawable instanceof BitmapDrawable) { 
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; 
        Bitmap bitmap = bitmapDrawable.getBitmap(); 
        bitmap.recycle(); 
        imageView.setImageDrawable(setToNewDrawable); 
       } 
      } 
     } 
    } 
+0

是的,你不能檢查它是否來自資源,這是最好的解決方案。 – Techfist

相關問題