Example usage for android.graphics Bitmap getByteCount

List of usage examples for android.graphics Bitmap getByteCount

Introduction

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

Prototype

public final int getByteCount() 

Source Link

Document

Returns the minimum number of bytes that can be used to store this bitmap's pixels.

Usage

From source file:com.google.android.apps.santatracker.util.LruImageCache.java

public LruImageCache() {
    // Naive calculation of available memory: Use 1/8th of memory for cache
    int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    int cacheSize = maxMemory / 8;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override/*www.  ja v a  2  s  .co m*/
        protected int sizeOf(String key, Bitmap bitmap) {
            return bitmap.getByteCount() / 1024;
        }
    };
}

From source file:com.nf2m.util.ImageCache.java

/**
 * Get the size in bytes of UriObserver bitmap in UriObserver BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value//ww w  .j  av  a2 s . c  o m
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
private static int getBitmapSize(@NonNull BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (Utils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.yahoo.mobile.client.android.yodel.utils.MemoryCache.java

public MemoryCache() {
    int cacheSize = 10 * 1024 * 1024 / 1024; // 10 mB
    Log.i(LOG_TAG, "Image cache size: " + cacheSize + "kB");

    mCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override/*  w  w w. ja v a 2s  .c  om*/
        protected int sizeOf(String key, Bitmap value) {
            return value.getByteCount() / 1024;
        }
    };
}

From source file:com.amachikhin.vkmachikhin.utils.image_cache.ImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value/*w  ww .  jav  a  2  s . c  o  m*/
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return bitmap.getAllocationByteCount();
    }

    if (Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.shizhefei.view.largeimage.ImageManager.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // API 19
        return bitmap.getAllocationByteCount();
    }/*from  w ww  .ja v  a2 s. c o m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {// API
        return bitmap.getByteCount();
    }
    return bitmap.getRowBytes() * bitmap.getHeight(); // earlier version
}

From source file:com.mabi87.imageloader.ImageMemoryCache.java

private ImageMemoryCache() {

    mCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override/*from   ww  w .j  av a 2 s  .co m*/
        protected int sizeOf(String key, Bitmap bitmap) {
            return bitmap.getByteCount() / 1024;
        }
    };
}

From source file:io.apptik.multiview.common.BitmapLruCache.java

@Override
protected int sizeOf(Uri key, Bitmap value) {
    return value.getByteCount() / 1024;
}

From source file:com.androidpi.bricks.gallery.lru.cache.ImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from
 * Android 4.4 (KitKat) onward this returns the allocated memory size of the
 * bitmap which can be larger than the actual bitmap data byte count (in the
 * case it was re-used)./*from  ww w . j av a2 s .  co m*/
 *
 * @param value
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes
    // can potentially be
    // larger than bitmap byte count.
    if (AppUtil.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (AppUtil.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.andrewreitz.encryptedcamera.cache.ThumbnailCache.java

@Override
protected int sizeOf(String key, Bitmap value) {
    // Return size of in-memory Bitmap, counted against maxSizeBytes
    return value.getByteCount();
}

From source file:com.sughimura.samplebitmaps.util.ImageCache.java

/**
 * Get the size in bytes of a bitmap in a BitmapDrawable. Note that from Android 4.4 (KitKat)
 * onward this returns the allocated memory size of the bitmap which can be larger than the
 * actual bitmap data byte count (in the case it was re-used).
 *
 * @param value//w  w  w.  j a va2  s  .com
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    // From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
    // larger than bitmap byte count.
    if (com.sughimura.samplebitmaps.util.Utils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

    if (com.sughimura.samplebitmaps.util.Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }

    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}