Example usage for android.graphics Bitmap getRowBytes

List of usage examples for android.graphics Bitmap getRowBytes

Introduction

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

Prototype

public final int getRowBytes() 

Source Link

Document

Return the number of bytes between rows in the bitmap's pixels.

Usage

From source file:Main.java

public static int getByteCount(Bitmap bitmap) {
    // This approach invokes API Level 1 methods unlike the Bitmap.getBytesCount() one from API level 12.
    return bitmap != null ? bitmap.getRowBytes() * bitmap.getHeight() : 0;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static int getSizeInBytes(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    } else {/* ww w.  j a v  a2 s.c  om*/
        return bitmap.getRowBytes() * bitmap.getHeight();
    }
}

From source file:Main.java

/**
 * Returns the in memory size of the given {@link Bitmap}.
 *//*from  ww w  . ja  v  a  2s  .  c  om*/
public static int getSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= 19) {
        return bitmap.getAllocationByteCount();
    } else {
        return bitmap.getHeight() * bitmap.getRowBytes();
    }
}

From source file:com.micabytes.gfx.ImageHandler.java

private static void initCache() {
    int memoryClass = ((ActivityManager) GameApplication.getInstance()
            .getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    int memoryCacheSize = MEGABYTE * MEGABYTE * memoryClass / 8;
    memoryCache = new LruCache<Integer, Bitmap>(memoryCacheSize) {
        @Override//from w ww.  j a va 2  s  . com
        protected int sizeOf(Integer key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}

From source file:Main.java

@TargetApi(12)
public static int getBitmapSize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }/*from   ww w. j a v  a  2 s. c o m*/
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:Main.java

/**
 * Get the size in bytes of a bitmap.//www .  ja v a  2 s . c o  m
 * @param bitmap
 * @return size in bytes
 */
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:Main.java

/**
 * Finds the percentage of pixels that do are empty.
 *
 * @param bitmap input bitmap// w w  w . ja  v  a 2s . c  o  m
 * @return a value between 0.0 to 1.0 . Note the method will return 0.0 if either of bitmaps are null nor of same size.
 *
 */
public static float getTransparentPixelPercent(Bitmap bitmap) {

    if (bitmap == null) {
        return 0f;
    }

    ByteBuffer buffer = ByteBuffer.allocate(bitmap.getHeight() * bitmap.getRowBytes());
    bitmap.copyPixelsToBuffer(buffer);

    byte[] array = buffer.array();

    int len = array.length;
    int count = 0;

    for (int i = 0; i < len; i++) {
        if (array[i] == 0) {
            count++;
        }
    }

    return ((float) (count)) / len;
}

From source file:Main.java

public static long getBitmapsize(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }/*  w  ww  .ja v  a 2  s  .c o  m*/
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();

}

From source file:Main.java

/**
 * Get the size in bytes of a bitmap.//from w  w w.j  a  va2  s  .co  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:Main.java

public static int getDrawableSize(Drawable drawable) {
    if (drawable == null) {
        return 0;
    }/*from   www.  j  a  va  2s . c  om*/
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    } else {
        return bitmap.getRowBytes() * bitmap.getHeight();
    }
}