Example usage for android.graphics Bitmap isRecycled

List of usage examples for android.graphics Bitmap isRecycled

Introduction

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

Prototype

public final boolean isRecycled() 

Source Link

Document

Returns true if this bitmap has been recycled.

Usage

From source file:Main.java

public static Bitmap rotateBitmapNoRecycle(Bitmap b, int degrees) {
    if (degrees != 0 && b != null && !b.isRecycled()) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);
        try {/* w  w  w .j ava 2  s  . c om*/
            Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
            return b2;
        } catch (OutOfMemoryError ex) {
        }
    }
    return b;
}

From source file:Main.java

public static final void recycle(Bitmap bitmap) {
    System.out.println("==recycle==");
    if (bitmap != null && !bitmap.isRecycled()) {
        System.out.println("--true");
        bitmap.recycle();/*from   ww  w .  j  a  v a2 s. c o m*/
        bitmap = null;
        System.gc();
    }
}

From source file:Main.java

public static byte[] bitmapDecode(Bitmap bmp) throws IOException {
    if (bmp != null && bmp.isRecycled())
        return null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    if (bmp == null) {
        // Resources res=context.getResources();
        // bmp=BitmapFactory.decodeResource(res,R.drawable.icon);
        // System.out.println("bitmapDecode@CDBPersistent----exception bmp is null,use default book");
        return null;
    }/*from   w ww  . j  av a 2  s .com*/

    bmp.compress(Bitmap.CompressFormat.PNG, 10, out);

    byte[] array = null;
    try {
        array = out.toByteArray();
    } catch (OutOfMemoryError e) {
        Log.e("arrayoom", "", e);
    }
    return array;
}

From source file:Main.java

public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {
    if (bmp == null || bmp.isRecycled())
        return null;
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, output);
    if (needRecycle) {
        bmp.recycle();//  www. jav a2s. co m
    }

    byte[] result = output.toByteArray();
    try {
        output.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static void recycleImageView(View view) {
    if (view == null)
        return;/*from   w  w  w.  j  a v a2  s  .  c om*/
    if (view instanceof ImageView) {
        Drawable drawable = ((ImageView) view).getDrawable();
        if (drawable instanceof BitmapDrawable) {
            Bitmap bmp = ((BitmapDrawable) drawable).getBitmap();
            if (bmp != null && !bmp.isRecycled()) {
                ((ImageView) view).setImageBitmap(null);
                bmp.recycle();
                bmp = null;
            }
        }
    }
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap b, int degrees) {
    if (degrees != 0 && b != null && !b.isRecycled()) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);
        try {/*from   www  . j  a  v a  2 s  .com*/
            Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
            if (b != b2) {
                b.recycle();
            }
            b = b2;
        } catch (OutOfMemoryError ex) {
        }
    }
    return b;
}

From source file:Main.java

public static void clearImageView(ImageView imageView) {
    if (!(imageView.getDrawable() instanceof BitmapDrawable)) {
        return;// w ww  .  j a v  a2s .c  o m
    }
    Bitmap drawable = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    if (drawable != null && !drawable.isRecycled()) {
        drawable.recycle();
    }
    imageView.setImageDrawable(null);
}

From source file:Main.java

public static Bitmap imageWithFixedRotation(Bitmap bm, int degrees) {
    if (bm == null || bm.isRecycled())
        return null;

    if (degrees == 0)
        return bm;

    final Matrix matrix = new Matrix();
    matrix.postRotate(degrees);//from  w ww . j  ava  2 s. com
    Bitmap result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
    if (result != bm)
        bm.recycle();
    return result;

}

From source file:Main.java

private final static void recycle(Bitmap... bitmaps) {
    if (bitmaps == null || bitmaps.length == 0) {
        return;/*from w  w  w  . j  a va  2  s  . c om*/
    }
    for (Bitmap bitmap : bitmaps) {
        if (bitmap == null) {
            continue;
        }
        if (!bitmap.isRecycled()) {
            bitmap.recycle();
            continue;
        }
        bitmap = null;
    }
    System.gc();
}

From source file:Main.java

public static Bitmap getRoundImage(Bitmap oriImg, boolean recycleOld) {

    Bitmap targetBitmap = null;//from  www. java2s.c o  m

    if (oriImg != null && !oriImg.isRecycled()) {
        int size = Math.min(oriImg.getWidth(), oriImg.getHeight());
        int targetWidth = size;
        int targetHeight = size;

        targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(targetBitmap);

        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawCircle(targetWidth / 2f, targetHeight / 2f, targetWidth / 2f, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(oriImg, new Rect(0, 0, size, size), new Rect(0, 0, targetWidth, targetHeight), paint);

        if (recycleOld) {
            oriImg.recycle();
        }
    }
    return targetBitmap;
}