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 getRoundAngleImage(Bitmap bitmap, int pixels, boolean recycleOld) {
    Bitmap output = null;/*  ww w. j  a  va2 s. c om*/
    if (bitmap != null && !bitmap.isRecycled()) {
        output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        final float roundPx = pixels;

        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        canvas.drawARGB(0, 0, 0, 0);
        //            paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        if (recycleOld)
            bitmap.recycle();
        return output;
    }
    return output;
}

From source file:Main.java

public static Bitmap toAlpha(Bitmap src, Boolean recycle) {
    if (isEmptyBitmap(src))
        return null;
    Bitmap ret = src.extractAlpha();/*from   ww  w.  j  a  v a 2 s.co m*/
    if (recycle && !src.isRecycled())
        src.recycle();
    return ret;
}

From source file:Main.java

public static File saveBitmapToExternal(Bitmap bitmap, String targetFileDirPath) {
    if (bitmap == null || bitmap.isRecycled()) {
        return null;
    }//ww  w.  j  a  v  a 2s  .  com

    File targetFileDir = new File(targetFileDirPath);
    if (!targetFileDir.exists() && !targetFileDir.mkdirs()) {
        return null;
    }

    File targetFile = new File(targetFileDir, UUID.randomUUID().toString());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(targetFile);
        baos.writeTo(fos);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } finally {
        try {
            baos.flush();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            if (fos != null) {
                fos.flush();
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return targetFile;
}

From source file:com.crossbow.volley.toolbox.CrossbowImageCache.java

private static boolean bitmapCanBeReused(Bitmap bitmap) {
    return bitmap != null && !bitmap.isRecycled() && bitmap.isMutable();
}

From source file:Main.java

public static Bitmap decodeResourcesBitmap(Context context, int res) {
    boolean bool = BITMAP_CACHE.containsKey(Integer.valueOf(res));
    Bitmap localBitmap = null;
    if (bool) {/*from   www. j av  a  2 s  . c  o m*/
        localBitmap = (Bitmap) BITMAP_CACHE.get(Integer.valueOf(res));
    }
    if ((localBitmap == null) || (localBitmap.isRecycled())) {
        localBitmap = BitmapFactory.decodeStream(context.getResources().openRawResource(res));
        BITMAP_CACHE.put(Integer.valueOf(res), localBitmap);
    }
    return localBitmap;
}

From source file:Main.java

public static Bitmap decodeResourcesBitmap(Context paramContext, int paramInt) {
    boolean bool = RESOURCES_BITMAP_CACHE.containsKey(Integer.valueOf(paramInt));
    Bitmap localBitmap = null;
    if (bool) {//from  ww  w.j  ava2  s  .c o  m
        localBitmap = (Bitmap) RESOURCES_BITMAP_CACHE.get(Integer.valueOf(paramInt));
    }
    if ((localBitmap == null) || (localBitmap.isRecycled())) {
        localBitmap = BitmapFactory.decodeStream(paramContext.getResources().openRawResource(paramInt));
        RESOURCES_BITMAP_CACHE.put(Integer.valueOf(paramInt), localBitmap);
    }
    return localBitmap;
}

From source file:Main.java

public static int[] getImageSize(Context context, int drawableId) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId);
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (bitmap != null && bitmap.isRecycled()) {
        bitmap.recycle();/*ww w . j  a v  a  2s . c o m*/
    }
    int size[] = { width, height };
    return size;
}

From source file:Main.java

public static byte[] Bitmap2Bytes(Bitmap bm, int ratio) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, ratio, baos);
    //add/* ww w  . j a v  a  2  s . c o  m*/
    if (bm != null && !bm.isRecycled()) {
        bm.recycle();
        bm = null;
    }
    return baos.toByteArray();
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap source, int degree) {
    Matrix matrix = new Matrix();
    matrix.postRotate(degree);/*from ww w  . ja v  a 2  s  . com*/
    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 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 ww w .  j  a  v a  2 s.  c o m
    if (b != null && !b.isRecycled()) {
        b.recycle();
        b = null;
    }
    return rotaBitmap;
}