Example usage for android.graphics Bitmap getAllocationByteCount

List of usage examples for android.graphics Bitmap getAllocationByteCount

Introduction

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

Prototype

public final int getAllocationByteCount() 

Source Link

Document

Returns the size of the allocated memory used to store this bitmap's pixels.

Usage

From source file:Main.java

/**
 * Method to get the number of bytes of the source Bitmap.
 *
 * @param source The source Bitmap./*from  w  w w  . ja  v a  2s.c o m*/
 * @return The number of bytes of the source Bitmap.
 */
private static int byteSizeOf(Bitmap source) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        return source.getRowBytes() * source.getHeight();
    } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return source.getByteCount();
    } else {
        return source.getAllocationByteCount();
    }
}

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();
    }//  ww  w  .j a  va2s. com

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

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

From source file:io.indy.seni.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//from  w  w w  . ja v a 2 s.  c  om
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

    return bitmap.getAllocationByteCount();
    /*
    // 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:Main.java

/**
 * @return size in bytes of the underlying bitmap
 *//*from  www  . j  a  v a2  s  .  c  o m*/
@SuppressLint("NewApi")
public static int getSizeInBytes(@Nullable Bitmap bitmap) {
    if (bitmap == null) {
        return 0;
    }

    // There's a known issue in KitKat where getAllocationByteCount() can throw an NPE. This was
    // apparently fixed in MR1: http://bit.ly/1IvdRpd. So we do a version check here, and
    // catch any potential NPEs just to be safe.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
        try {
            return bitmap.getAllocationByteCount();
        } catch (NullPointerException npe) {
            // Swallow exception and try fallbacks.
        }
    }

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

    // Estimate for earlier platforms. Same code as getByteCount() for Honeycomb.
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:Main.java

/**
 * @return size in bytes of the underlying bitmap
 *//*from   w ww.ja  v  a 2s . c o m*/
@SuppressLint("NewApi")
public static int getSizeInBytes(@Nullable Bitmap bitmap) {
    if (bitmap == null) {
        return 0;
    }

    // There's a known issue in KitKat where getAllocationByteCount() can throw an NPE. This was
    // apparently fixed in MR1: http://bit.ly/1IvdRpd. So we do a version check here, and
    // catch any potential NPEs just to be safe.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
        try {
            return bitmap.getAllocationByteCount();
        } catch (NullPointerException npe) {
            // Swallow exception and try fallbacks.
        }
    }

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

    // Estimate for earlier platforms.
    return bitmap.getWidth() * bitmap.getRowBytes();
}

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 ww. j  a va 2 s. c  o  m
    return bitmap.getByteCount();
}

From source file:com.android.volley.cache.BitmapImageCache.java

/**
 * Get the size in bytes of a bitmap./*from  www.j  av  a  2  s. c  o m*/
 */
@TargetApi(19)
public static int getBitmapSize(Bitmap bitmap) {
    // 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.sqkj.engine.image.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//from   w  w w  .  j  ava 2 s .  co  m
 * @return size in bytes
 */
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 (SdkUtils.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

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

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

From source file:com.chanlytech.unicorn.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/*from w  w  w  .  ja  v a  2 s .c  o  m*/
 *
 * @return size in bytes
 */
@TargetApi(Build.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 (AndroidVersion.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

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

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

From source file:com.higgses.griffin.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//from  w w  w.  ja  v  a  2  s .com
 *
 * @return size in bytes
 */
@TargetApi(Build.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 (GriUAndroidVersion.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

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

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