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 String imageToLocal(Bitmap bitmap, String name) {
    String path = null;//from w ww  .  ja va 2  s .  com
    try {
        if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            return null;
        }
        String filePath = Environment.getExternalStorageDirectory().getPath() + "/cache/";
        File file = new File(filePath, name);
        if (file.exists()) {
            path = file.getAbsolutePath();
            return path;
        } else {
            file.getParentFile().mkdirs();
        }
        file.createNewFile();

        OutputStream outStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();
        if (!bitmap.isRecycled()) {
            bitmap.recycle();
        }

        path = file.getAbsolutePath();
    } catch (Exception e) {
    }
    return path;
}

From source file:com.c4mprod.utils.ImageManager.java

public static Bitmap quickCachedImage(String url) {
    if (instance != null && url != null) {
        Bitmap cachedBitmap = instance.mImageLiveCache.get(url);
        if (cachedBitmap != null && !cachedBitmap.isRecycled()) {
            return cachedBitmap.copy(Config.ARGB_8888, false);
        }/*from   w w  w.j av  a2s .  com*/
    }
    return null;
}

From source file:Main.java

public static Bitmap rotateBitmapInNeeded(String path, Bitmap srcBitmap) {
    if (TextUtils.isEmpty(path) || srcBitmap == null) {
        return null;
    }/*from w  w  w  . j ava2s  .com*/

    ExifInterface localExifInterface;
    try {
        localExifInterface = new ExifInterface(path);
        int rotateInt = localExifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        float rotate = getImageRotate(rotateInt);
        if (rotate != 0) {
            Matrix matrix = new Matrix();
            matrix.postRotate(rotate);
            Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(),
                    matrix, false);
            if (dstBitmap == null) {
                return srcBitmap;
            } else {
                if (srcBitmap != null && !srcBitmap.isRecycled()) {
                    srcBitmap.recycle();
                }
                return dstBitmap;
            }
        } else {
            return srcBitmap;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return srcBitmap;
    }
}

From source file:com.therealjoshua.essentials.bitmaploader.cache.LruCacheAdapter.java

@Override
public boolean hasObject(String id) {
    if (id == null)
        return false;
    Bitmap bm = lruCache.get(id);
    return (bm != null && !bm.isRecycled());
}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap getCircularBitmapWithWhiteBorder(Bitmap bitmap, int borderWidth) {
    if (bitmap == null || bitmap.isRecycled()) {
        return null;
    }//from   w w  w  . j  a  v a  2s . c om

    final int width = bitmap.getWidth() + borderWidth;
    final int height = bitmap.getHeight() + borderWidth;

    Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(shader);

    Canvas canvas = new Canvas(canvasBitmap);
    float radius = width > height ? ((float) height) / 2f : ((float) width) / 2f;
    canvas.drawCircle(width / 2, height / 2, radius, paint);
    paint.setShader(null);
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(borderWidth);
    canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2, paint);
    return canvasBitmap;
}

From source file:com.badou.mworking.net.bitmap.BitmapLruCache.java

public void putCircleBitmap(String url, Bitmap bitmap) {
    if (bitmap == null || bitmap.isRecycled()) {
        remove(url + SUFFIX_CIRCLE);//from w  w  w.j  a v  a2  s. co  m
    } else {
        put(url + SUFFIX_CIRCLE, bitmap);
    }
}

From source file:com.badou.mworking.net.bitmap.BitmapLruCache.java

public void putOriginBitmap(String url, Bitmap bitmap) {
    if (bitmap == null || bitmap.isRecycled()) {
        remove(url + SUFFIX_ORIGIN);/* w w w  .  ja  v  a  2  s  .  c o m*/
    } else {
        put(url + SUFFIX_ORIGIN, bitmap);
    }
}

From source file:com.badou.mworking.net.bitmap.BitmapLruCache.java

@Override
public void putBitmap(String url, Bitmap bitmap) {
    if (bitmap == null || bitmap.isRecycled()) {
        remove(url);//from   w  ww.  j  a va  2s .  c  o m
    } else {
        put(url, bitmap);
    }
}

From source file:com.jcsoluciones.superdt.utilities.RecyclingBitmapDrawable.java

private synchronized boolean hasValidBitmap() {
    Bitmap bitmap = getBitmap();
    return bitmap != null && !bitmap.isRecycled();
}

From source file:hochschuledarmstadt.photostream_tools.adapter.LruBitmapCache.java

public void destroy() {
    hitCountMap.clear();//from w  w  w  . j a v  a  2s .c o m
    Collection<Bitmap> values = removedBitmaps.values();
    for (Bitmap b : values) {
        if (!b.isRecycled())
            b.recycle();
    }
    removedBitmaps.clear();
    evictAll();
}