Created
October 16, 2015 08:58
-
-
Save bitristan/ec10a1d9b8b2af1d1334 to your computer and use it in GitHub Desktop.
Recycle ImageView Bitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Recycle src of ImageView | |
private static void recycleImageViewBitMap(ImageView imageView) { | |
if (imageView != null) { | |
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable(); | |
rceycleBitmapDrawable(bd); | |
} | |
} | |
private static void rceycleBitmapDrawable(BitmapDrawable bitmapDrawable) { | |
if (bitmapDrawable != null) { | |
Bitmap bitmap = bitmapDrawable.getBitmap(); | |
rceycleBitmap(bitmap); | |
} | |
bitmapDrawable = null; | |
} | |
private static void rceycleBitmap(Bitmap bitmap) { | |
if (bitmap != null && !bitmap.isRecycled()) { | |
bitmap.recycle(); | |
bitmap = null; | |
} | |
} | |
// Recycle Background of ImageView | |
public static void recycleBackgroundBitMap(ImageView view) { | |
if (view != null) { | |
BitmapDrawable bd = (BitmapDrawable) view.getBackground(); | |
rceycleBitmapDrawable(bd); | |
} | |
} | |
public static void recycleImageViewBitMap(ImageView imageView) { | |
if (imageView != null) { | |
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable(); | |
rceycleBitmapDrawable(bd); | |
} | |
} | |
private static void rceycleBitmapDrawable(BitmapDrawable bitmapDrawable) { | |
if (bitmapDrawable != null) { | |
Bitmap bitmap = bitmapDrawable.getBitmap(); | |
rceycleBitmap(bitmap); | |
} | |
bitmapDrawable = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment