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:so.contacts.hub.basefunction.imageloader.DataCache.java

/**
 * Get the size in bytes of a bitmap. Bitmapbyte?
 * // ww  w .  j a  va 2s.c  om
 * @param bitmap
 * @return size in bytes
 */
@TargetApi(12)
public static int getBitmapSize(Bitmap bitmap) {
    if (CacheUtils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:org.tigase.messenger.phone.pro.utils.ImageHelper.java

protected static void initialize(Context context) {
    if (memCache == null) {
        // Get memory class of this device, exceeding this amount will throw
        // an OutOfMemory exception.
        final int memClass = ((android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
                .getMemoryClass();//from w  w w.j  a  v a2s.  c  o m

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = 1024 * 1024 * memClass / 8;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
            memCache = new LruCache<String, Bitmap>(cacheSize) {
                @TargetApi(12)
                @Override
                protected int sizeOf(String key, Bitmap bitmap) {
                    // The cache size will be measured in bytes rather than
                    // number of items. Ignoring placeholder bitmap as well.
                    return placeHolders.contains(bitmap) ? 0 : bitmap.getByteCount();
                }
            };
        } else {
            // below SDK 12 there is no getByteCount method
            memCache = new LruCache<String, Bitmap>(cacheSize) {
                @Override
                protected int sizeOf(String key, Bitmap bitmap) {
                    // The cache size will be measured in bytes rather than
                    // number of items. Ignoring placeholder bitmap as well.
                    return placeHolders.contains(bitmap) ? 0 : (bitmap.getRowBytes() * bitmap.getHeight());
                }
            };
        }

        // maps images cache
        BitmapDiskLruCache diskCache = new BitmapDiskLruCache();
        diskCache.initialize(context, "maps", 10 * 1024 * 1024);
        diskCaches.put("maps", diskCache);

        // images from files shared with or by us
        diskCache = new BitmapDiskLruCache();
        diskCache.initialize(context, "images-mini", 10 * 1024 * 1024);
        diskCaches.put("images-mini", diskCache);
    }
}

From source file:id.wibisana.priadimulia.imagecaching.cache.ImageCache.java

@TargetApi(12)
public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }/*  ww  w.  j  av a 2 s .  co m*/

    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.ttoview.nakayosi.ttoview.util.picker.image.ImageCache.java

@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(RecyclingBitmapWrapper 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();
    }//from  w ww  . j av a 2s  . com

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

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

From source file:org.tigase.mobile.utils.AvatarHelper.java

public static void initilize(Context context_) {
    if (avatarCache == null) {
        context = context_;/*  ww w.  j a  v  a2  s  .  com*/

        density = context.getResources().getDisplayMetrics().density;
        defaultAvatarSize = Math.round(density * 50);

        // Get memory class of this device, exceeding this amount will throw
        // an
        // OutOfMemory exception.
        final int memClass = ((android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
                .getMemoryClass();

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = 1024 * 1024 * memClass / 8;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
            avatarCache = new LruCache<BareJID, Bitmap>(cacheSize) {
                @TargetApi(12)
                @Override
                protected int sizeOf(BareJID key, Bitmap bitmap) {
                    // The cache size will be measured in bytes rather than
                    // number of items. Ignoring placeholder bitmap as well.
                    return bitmap == mPlaceHolderBitmap ? 0 : bitmap.getByteCount();
                }
            };
        } else {
            // below SDK 12 there is no getByteCount method
            avatarCache = new LruCache<BareJID, Bitmap>(cacheSize) {
                @Override
                protected int sizeOf(BareJID key, Bitmap bitmap) {
                    // The cache size will be measured in bytes rather than
                    // number of items. Ignoring placeholder bitmap as well.
                    return bitmap == mPlaceHolderBitmap ? 0 : (bitmap.getRowBytes() * bitmap.getHeight());
                }
            };
        }

        mPlaceHolderBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.user_avatar);
    }
}

From source file:com.intelerad.android.portal.ImageCache.java

/**
 * Get the size in bytes of a bitmap./*from   ww w  . j  a  va2  s  .  com*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static int getBitmapSize(Bitmap bitmap) {
    if (UiUtils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.ruesga.rview.misc.BitmapUtils.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static int byteSizeOf(Bitmap bitmap) {
    if (AndroidHelper.isKitkatOrGreater()) {
        return bitmap.getAllocationByteCount();
    }//  w  w  w .ja  v a  2 s.c o  m
    return bitmap.getByteCount();
}

From source file:com.egoists.coco_nut.android.cache.ImageCache.java

/**
 * Get the size in bytes of a bitmap.//from w ww . j av  a 2  s  .c  om
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static int getBitmapSize(Bitmap bitmap) {
    if (EtcUtils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:gr.unfold.android.tsibato.images.ImageCache.java

@TargetApi(12)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    if (Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }//w ww .j av  a2s.  c o m
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.sven.im.video.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).//www  . j  a v a  2  s.com
 *
 * @param value
 * @return size in bytes
 */
@TargetApi(19)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

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

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