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:Main.java

/**
 * TODO doc//from   ww  w  .  j a v a  2 s  .c o  m
 *
 * @param data
 * @return
 */
private static int byteSizeOf(Bitmap data) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        return data.getRowBytes() * data.getHeight();
    } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return data.getByteCount();
    } else {
        return data.getAllocationByteCount();
    }
}

From source file:Main.java

/**
 * Method to get the number of bytes of the source Bitmap.
 *
 * @param source The source Bitmap.// w  w  w. j a va  2 s . co 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:Main.java

public static long getBitmapSize(Bitmap bitmap) {
    // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // API19
    // return bitmap.getAllocationByteCount();
    // }/*  w  ww  . j a v a2s  . co m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {// API12
        return bitmap.getByteCount();
    }
    return bitmap.getRowBytes() * bitmap.getHeight(); // earlier version
}

From source file:Main.java

@SuppressLint("NewApi")
public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // API 19
        return bitmap.getAllocationByteCount();
    }/*from  www  .ja  va2  s.c om*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {// API 12
        return bitmap.getByteCount();
    }
    return bitmap.getRowBytes() * bitmap.getHeight(); // earlier version
}

From source file:Main.java

/**
 * returns the bytesize of the give bitmap
 *//*  ww w. j av  a  2s . co m*/
public static int byteSizeOf(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return bitmap.getAllocationByteCount();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    } else {
        return bitmap.getRowBytes() * bitmap.getHeight();
    }
}

From source file:com.manning.androidhacks.hack040.util.Utils.java

/**
 * Get the size in bytes of a bitmap.//from  w w w  .j  ava 2 s . c  o m
 * 
 * @param bitmap
 * @return size in bytes
 */
@SuppressLint("NewApi")
public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.bluepixel.android.sgpool.util.BitmapCache.java

/**
 * Get the size in bytes of a bitmap./*www  .ja va  2  s  . com*/
 */
public static int getBitmapSize(Bitmap bitmap) {
    return bitmap.getByteCount();
}

From source file:it.michelepiccirillo.paperplane.client.Picture.java

public static void setCacheSize(int cacheSize) {
    Picture.cacheSize = cacheSize;/* w w w . j av a 2  s  .  c o m*/
    cache = new LruCache<Long, Bitmap>(cacheSize) {
        protected int sizeOf(Long key, Bitmap value) {
            return value.getByteCount();
        };
    };
}

From source file:Main.java

public static int getSize(Bitmap image) {
    int size = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //API 19
        size = image.getAllocationByteCount();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {//API 12
        size = image.getByteCount();
    } else {//from ww w .  j  a va  2 s . c  o  m
        size = image.getRowBytes() * image.getHeight();
    }
    return size;
}

From source file:android.com.example.contactslist.util.ImageCache.java

/**
 * Get the size in bytes of a bitmap./*from   w  w  w.  j  a va  2  s  .  co m*/
 *
 * @param bitmap The bitmap to calculate the size of.
 * @return size of bitmap in bytes.
 */
@TargetApi(12)
public static int getBitmapSize(Bitmap bitmap) {
    if (Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}