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();
}
我想回收位图,除了资源drawable ...
答案 0 :(得分: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);
}
}
}
}