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

public static int getSize(Bitmap bitmap) {
    if (bitmap == null) {
        return 0;
    }/*w  w w  .j  av a 2 s  . c  o m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    } else {
        return bitmap.getRowBytes() * bitmap.getHeight();
    }
}

From source file:Main.java

@SuppressLint("NewApi")
public static int getBitmapSize(Bitmap bitmap) {
    if (bitmap == null) {
        return 0;
    }//from ww w . ja va2 s . co m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    } else {
        return bitmap.getRowBytes() * bitmap.getHeight();
    }
}

From source file:com.hellosky.recyclingimageloader.util.ImageMemoryCache.java

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

    if (Utils.hasHoneycombMR1()) {
        return bitmap.getByteCount();
    }//from   ww w .  ja  v  a2 s  . c o  m
    // Pre HC-MR1
    return bitmap.getRowBytes() * bitmap.getHeight();
}

From source file:Main.java

public static long getBitmapSize(Bitmap bitmap) {
    long size = 0;
    if (bitmap != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
            return bitmap.getByteCount();
        } else {//from w w w  .  j av  a  2 s.  c o m
            // Pre HC-MR1
            return bitmap.getRowBytes() * bitmap.getHeight();
        }
    }
    return size;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static int sizeOf(Bitmap data) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        return data.getRowBytes() * data.getHeight();
    } else {//from w ww .  jav  a 2  s  .  c  o m
        return data.getByteCount();
    }
}

From source file:Main.java

public static int getByteCount(Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= 19) {
        return bitmap.getAllocationByteCount();
    } else if (Build.VERSION.SDK_INT >= 12) {
        return bitmap.getByteCount();
    } else {//  www  .  ja v  a 2 s  . c o  m
        return getByteCount(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    }
}

From source file:inc.bait.jubilee.model.helper.util.ImgCache.java

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

From source file:org.chromium.chrome.browser.download.ui.ThumbnailProviderImpl.java

private static LruCache<String, Bitmap> getBitmapCache() {
    ThreadUtils.assertOnUiThread();//from w w  w  . j av a 2 s .c o m

    LruCache<String, Bitmap> cache = sBitmapCache == null ? null : sBitmapCache.get();
    if (cache != null)
        return cache;

    // Create a new weakly-referenced cache.
    cache = new LruCache<String, Bitmap>(MAX_CACHE_BYTES) {
        @Override
        protected int sizeOf(String key, Bitmap thumbnail) {
            return thumbnail == null ? 0 : thumbnail.getByteCount();
        }
    };
    sBitmapCache = new WeakReference<>(cache);
    return cache;
}

From source file:Main.java

public static byte[] toByteArrayNew(Bitmap source) {
    //int size = source.getRowBytes() * source.getHeight();
    int size = source.getByteCount();
    ByteBuffer byteBuffer = ByteBuffer.allocate(size);
    source.copyPixelsToBuffer(byteBuffer);
    byteBuffer.rewind();// w w  w.j  ava2s .  c o  m
    byte[] b = byteBuffer.array();
    return b;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static int sizeOf(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 {/* w  w  w .  ja va2  s .c  om*/
        return data.getAllocationByteCount();
    }
}