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 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();// ww w . jav a  2 s  .  co m
    } else {
        size = image.getRowBytes() * image.getHeight();
    }
    return size;
}

From source file:Main.java

/**
 * Compares two bitmaps and gives the percentage of similarity
 *
 * @param bitmap1 input bitmap 1/* w  w  w .ja v a 2 s  .  c om*/
 * @param bitmap2 input bitmap 2
 * @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 compareEquivalance(Bitmap bitmap1, Bitmap bitmap2) {

    if (bitmap1 == null || bitmap2 == null || bitmap1.getWidth() != bitmap2.getWidth()
            || bitmap1.getHeight() != bitmap2.getHeight()) {
        return 0f;
    }

    ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight() * bitmap1.getRowBytes());
    bitmap1.copyPixelsToBuffer(buffer1);

    ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight() * bitmap2.getRowBytes());
    bitmap2.copyPixelsToBuffer(buffer2);

    byte[] array1 = buffer1.array();
    byte[] array2 = buffer2.array();

    int len = array1.length; // array1 and array2 will be of some length.
    int count = 0;

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

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

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

/**
 * Get the size in bytes of a bitmap.//from  ww  w.  j  a  v  a 2s  .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:android.com.example.contactslist.util.ImageCache.java

/**
 * Get the size in bytes of a bitmap.//from   w w w . jav a  2 s.  c  om
 *
 * @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();
}

From source file:br.com.mybaby.contatos.ImageCache.java

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

From source file:Main.java

@SuppressLint("NewApi")
public static int sizeOfBitmap(Bitmap bitmap) {
    if (bitmap == null) {
        return 0;
    }/* ww  w  .j  a v a2 s.co  m*/
    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.mallapp.utils.ImageCache.java

/**
 * Get the size in bytes of a bitmap./* w w w . j ava 2 s.c o 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:com.example.demo.util.ImageCache.java

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

From source file:com.seun.gallery.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 image// w w w.  j av  a  2s  .c  o  m
 * @return size in bytes
 */
public static int getBitmapSize(BitmapDrawable value) {
    Bitmap bitmap = value.getBitmap();

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

From source file:com.vinay.volley.lazyload.BitmapCache.java

/**
 * Get the size in bytes of a bitmap.// w  w w  .  j a v  a2s  .  co m
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static int getBitmapSize(Bitmap bitmap) {
    if (hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}