工具类:
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;
public class ImageUtil {
private static final String TAG = ImageUtil.class.getSimpleName();
public static void releaseImageViewResource(ImageView imageView) {
if (imageView != null) {
Drawable background = imageView.getBackground();
Drawable drawable = imageView.getDrawable();
imageView = null;
if (background instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) background;
Bitmap bitmap = bitmapDrawable.getBitmap();
bitmapDrawable = null;
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
bitmap = null;
}
}
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
bitmapDrawable = null;
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
bitmap = null;
}
}
}
}
}