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:com.common.library.bitmap.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  ww .j  a  v a2  s  .co  m*/
 * @return size in bytes
 */
@TargetApi(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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return bitmap.getAllocationByteCount();
    }

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

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

From source file:air.com.snagfilms.utils.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).// ww  w . j  a  va  2  s . co  m
 * 
 * @param value
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.JELLY_BEAN)
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 (Utils.hasKitKat()) { return bitmap.getAllocationByteCount(); }
     */

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

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

From source file:com.chatwingsdk.utils.BitmapLruCache.java

@Override
@TargetApi(12)/*  w  w  w  . j a  va  2  s  .  c  o  m*/
protected int sizeOf(String key, Bitmap value) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        return value.getByteCount() / 1024;
    } else {
        return (value.getRowBytes() * value.getHeight()) / 1024;
    }
}

From source file:com.bluetech.gallery5.util.ImageCache.java

/**
 * @param candidate - Bitmap to check/*from   w ww.jav  a2s .  c o  m*/
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use with
 *      <code>targetOptions</code>
 */
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getByteCount();
    //END_INCLUDE(can_use_for_inbitmap)
}

From source file:com.extradea.framework.images.cache.LruBitmapCache.java

public LruBitmapCache(int size) {
    imageTempCache = new HashMap<String, WeakReference<Bitmap>>();
    imageCache = new LruCache<String, Bitmap>(size) {
        @Override/* ww w .  jav  a 2 s. c o  m*/
        protected int sizeOf(String key, Bitmap value) {
            if (Build.VERSION.SDK_INT >= 12) {
                return value.getByteCount();
            } else {
                return value.getRowBytes() * value.getHeight();
            }
        }
    };
}

From source file:com.mimming.sugarglider.MapImageManager.java

private MapImageManager() {
    mapCache = new LruCache<String, Bitmap>(CACHE_SIZE) {
        protected int sizeOf(String key, Bitmap value) {
            return value.getByteCount() / 1024;
        }//from  w ww.  j av  a 2 s .  c om
    };
    mMapType = MapType.HIGH_CONTRAST;
}

From source file:com.cmgapps.android.util.BitmapCache.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override//from  w ww .  j  av  a 2 s.co m
protected int sizeOf(Integer key, Bitmap bitmap) {
    if (ApiUtils.hasKitKat()) {
        return bitmap.getAllocationByteCount() / 1024;
    } else if (ApiUtils.hasHoneycombMR1()) {
        return bitmap.getByteCount() / 1024;
    } else {
        return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024;
    }
}

From source file:com.frostwire.android.util.ImageCache.java

private InputStream getInputStream(Bitmap bmp) {
    ByteArrayOutputStream out = new ByteArrayOutputStream(bmp.getByteCount());
    bmp.compress(CompressFormat.PNG, 100, out);
    return new ByteArrayInputStream(out.toByteArray());
}

From source file:com.wj.android.wjframe.bitmap.BitmapMemoryCache.java

/**
 * @param maxSize ???kb/*from w  w w.j  a v a2  s.com*/
 */
@SuppressLint("NewApi")
private void init(int maxSize) {
    this.maxSize = maxSize;
    cache = new LruCache<String, Bitmap>(maxSize) {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            super.sizeOf(key, value);
            if (SystemTool.getSDKVersion() >= 12) {
                return value.getByteCount();
            } else {
                return value.getRowBytes() * value.getHeight();
            }
        }
    };
}

From source file:org.appcelerator.titanium.util.TiImageLruCache.java

@Override
protected int sizeOf(Integer key, Bitmap bitmap) {
    // The cache size will be measured in kilobytes rather than
    // number of items.
    if (android.os.Build.VERSION.SDK_INT > TiC.API_LEVEL_HONEYCOMB) {
        return bitmap.getByteCount() / 1024;
    } else {/* w  ww  .  java  2  s  .  c  o m*/
        return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
    }
}