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 rotaingImageView(int angle, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);//  ww  w.ja v  a2  s  .c  om
    System.out.println("angle2=" + angle);
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
            true);
    bitmap.recycle();
    return resizedBitmap;
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap source, int degree) {
    Matrix matrix = new Matrix();
    matrix.postRotate(degree);//w w  w.j  a v  a  2 s  . co  m
    Bitmap temp = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    if (null != source && !source.isRecycled()) {
        source.recycle();
        source = null;
    }
    return temp;
}

From source file:Main.java

public static Bitmap rotateImage(Bitmap bitmap, int rotate) {
    if (rotate != 0) {
        // rotate
        Matrix m = new Matrix();
        m.postRotate(rotate);/*from   w w w .  j a va 2 s .com*/
        Bitmap rotImage = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
        bitmap.recycle();
        System.gc();

        return rotImage;
    }
    return bitmap;
}

From source file:Main.java

public static void saveBitmapToFile(Bitmap bitmap, File file) {

    try {/*from   w w w .  j  ava 2  s  .  c  om*/
        BufferedOutputStream bStream = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(CompressFormat.JPEG, 100, bStream);
        bStream.flush();
        bStream.close();
        bitmap.recycle();
    } catch (IOException e) {
        // Log.d(TAG, e.toString());
    }
}

From source file:Main.java

public static Bitmap cropBitmap(Bitmap bitmap, Rect rect) {
    int w = rect.right - rect.left;
    int h = rect.bottom - rect.top;
    Bitmap ret = Bitmap.createBitmap(w, h, bitmap.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(bitmap, -rect.left, -rect.top, null);
    bitmap.recycle();
    return ret;//from w w  w . j a  va 2  s.com
}

From source file:Main.java

/**
 * Convert the Bitmap to ALPHA_8.  The old one will be recycled.
 *///from  w  ww  .  j a va2s.c om
static Bitmap toAlpha8(Bitmap src, boolean recycle) {
    if (!src.hasAlpha()) {
        src = redToAlpha(src, recycle);
        recycle = true;
    }

    Bitmap dest = src.copy(Bitmap.Config.ALPHA_8, false);
    if (recycle)
        src.recycle();
    return dest;
}

From source file:Main.java

public static void saveBitmap(File output, Bitmap bitmap) throws FileNotFoundException, IOException {
    FileOutputStream fos = new FileOutputStream(output);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
    fos.flush();/* ww w  .java 2  s  .  c o  m*/
    fos.close();
    bitmap.recycle();
    bitmap = null;
}

From source file:Main.java

public static Bitmap getRotateBitmap(Bitmap b, float rotateDegree) {
    Matrix matrix = new Matrix();
    matrix.postRotate((float) rotateDegree);
    Bitmap rotaBitmap = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, false);
    //add//from w  ww  .  j a v a2s  .  c o  m
    if (b != null && !b.isRecycled()) {
        b.recycle();
        b = null;
    }
    return rotaBitmap;
}

From source file:Main.java

public static Bitmap getPaintedBitmap(Bitmap bitmap, Paint paint, boolean deleteOld) {
    final Bitmap colorBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    final Canvas c = new Canvas(colorBitmap);
    c.drawBitmap(bitmap, 0, 0, paint);//from w w w.  jav  a 2  s  . c om
    if (deleteOld) {
        bitmap.recycle();
    }
    return colorBitmap;
}

From source file:com.actinarium.nagbox.common.ViewUtils.java

/**
 * Set custom icon and color for recents screen card
 *
 * @param activity Activity to configure
 * @param colorRes Color resource for recents screen card title
 * @param icon     Bitmap drawable resource to draw into recents screen card title
 *///from   ww w. ja  v a 2s. c  o  m
public static void setupRecentsIcon(Activity activity, @ColorRes int colorRes, @DrawableRes int icon) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return;
    }

    int color = ContextCompat.getColor(activity, colorRes);
    Bitmap bm = BitmapFactory.decodeResource(activity.getResources(), icon);
    ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(null, bm, color);

    activity.setTaskDescription(td);
    bm.recycle();
}