Example usage for android.graphics Bitmap recycle

List of usage examples for android.graphics Bitmap recycle

Introduction

In this page you can find the example usage for android.graphics Bitmap recycle.

Prototype

public void recycle() 

Source Link

Document

Free the native object associated with this bitmap, and clear the reference to the pixel data.

Usage

From source file:Main.java

public static Bitmap changeBitmap(Bitmap bitmap, int w, int h) {
    Bitmap localBitmap = ThumbnailUtils.extractThumbnail(bitmap, w, h);
    bitmap.recycle();
    return localBitmap;
}

From source file:Main.java

public static void recycleBitmapArr(Bitmap[] bmps) {
    for (int i = 0; i < bmps.length; i++) {
        Bitmap mBitmap = bmps[i];
        if (mBitmap != null && !mBitmap.isRecycled()) {
            mBitmap.recycle();
            mBitmap = null;//  w  w  w  .j  a  v a  2 s .c  o m
            System.gc();
            System.runFinalization();
            System.gc();
        }
    }
}

From source file:Main.java

/**
 * Recycle the bitmap with null checks./*w  w  w. ja va 2  s . com*/
 * If the bitmap is already recycled, do nothing.
 *
 * @param bitmap to recycle.
 */
public static void recycle(Bitmap bitmap) {
    if (bitmap == null || bitmap.isRecycled()) {
        return;
    }
    bitmap.recycle();
}

From source file:Main.java

/**
 * recycle bitmap//from ww  w.j  a  v  a2s  . co m
 * 
 * @param bitmap
 */
public static void recycle(Bitmap bitmap) {
    if (null == bitmap || bitmap.isRecycled()) {
        return;
    }
    bitmap.recycle();
    bitmap = null;
}

From source file:Main.java

public static void recycleSilently(Bitmap bitmap) {
    if (bitmap == null)
        return;// w ww. j  ava  2  s .  c  om
    try {
        bitmap.recycle();
    } catch (Throwable t) {
        Log.w(TAG, "unable recycle bitmap", t);
    }
}

From source file:Main.java

/**
 * Safely free all {@link Bitmap} in a bitmap {@link List}.
 * //from w  w  w .ja  va2 s.  co  m
 * @param bmpList
 *            Bitmap list.
 */
public final static void freeBitmapList(List<Bitmap> bmpList) {
    if (null != bmpList) {
        for (Bitmap bmp : bmpList) {
            if (null != bmp && !bmp.isRecycled()) {
                bmp.recycle();
            }
        }
        bmpList.clear();
    }
}

From source file:Main.java

static public int getImageSize(String albumArtPath) {
    if (albumArtPath != null) {
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inJustDecodeBounds = true;/*from w  ww.j av  a  2s . c  o m*/
        Bitmap bmTmp = BitmapFactory.decodeFile(albumArtPath, opts);
        if (bmTmp != null)
            bmTmp.recycle();
        return Math.max(opts.outWidth, opts.outWidth);
    }
    return 0;
}

From source file:Main.java

public static int getDominantColor(Bitmap bitmap) {
    Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, 1, 1, true);
    final int color = newBitmap.getPixel(0, 0);
    newBitmap.recycle();
    return color;
}

From source file:Main.java

public static int getImageHeight(final Context context, final int drawable) {
    int bg_height = 0;
    Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), drawable);
    bg_height = bmp.getHeight();/*  w w  w. jav a  2s.com*/
    bmp.recycle();
    return bg_height;
}

From source file:Main.java

public static void releaseBitmapArray(Bitmap[] bitmaps) {
    if (bitmaps != null) {
        try {//from www  .ja  v a 2s  . com
            for (Bitmap bitmap : bitmaps) {
                if (bitmap != null && !bitmap.isRecycled()) {
                    bitmap.recycle();
                }
            }
        } catch (Exception e) {
        }
    }
}