List of usage examples for android.graphics Bitmap getRowBytes
public final int getRowBytes()
From source file:com.sughimura.samplebitmaps.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//from w w w . j av a 2 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 (com.sughimura.samplebitmaps.util.Utils.hasKitKat()) { return bitmap.getAllocationByteCount(); } if (com.sughimura.samplebitmaps.util.Utils.hasHoneycombMR1()) { return bitmap.getByteCount(); } // Pre HC-MR1 return bitmap.getRowBytes() * bitmap.getHeight(); }
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/*w w w.j a v a 2 s. c om*/ * @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:com.yineng.ynmessager.cache.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)./*from ww w .ja v a 2s . c om*/ * * @param value * @return size in bytes */ @TargetApi(19) 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.getByteCount(); } if (Utils.hasHoneycombMR1()) { return bitmap.getByteCount(); } // Pre HC-MR1 return bitmap.getRowBytes() * bitmap.getHeight(); }
From source file:org.sickstache.helper.BannerCache.java
private BannerCache(Context c) { c = c.getApplicationContext();/*ww w .ja va 2 s . co m*/ this.cacheDir = new File(c.getExternalCacheDir(), cacheFolder); if (this.cacheDir.exists() == false) this.cacheDir.mkdirs(); int memClass = ((ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); // use half of the memory unless we have less then 32MB int cacheSize = memClass * 1024 * 1024 / 2; if (memClass < 32) cacheSize = memClass * 1024 * 1024 / 4; this.memCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.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).//w w w .j av a 2s . c om * * @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:org.couchtatertot.helper.PosterCache.java
private PosterCache(Context c) { this.cacheDir = new File(c.getExternalCacheDir(), cacheFolder); this.cacheDir.mkdirs(); int memClass = ((ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); // use half of the memory unless we have less then 32MB int cacheSize = memClass * 1024 * 1024 / 2; if (memClass < 32) cacheSize = memClass * 1024 * 1024 / 4; this.memCache = new LruCache<String, Bitmap>(cacheSize) { @Override//w ww . j av a 2 s .c o m protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:com.appsimobile.appsii.plugins.IconCache.java
@Inject public IconCache(ActivityManager activityManager) { final int memClass = activityManager.getMemoryClass(); int sizeInBytes = memClass * 1024 * 1024; int desiredSize = sizeInBytes / 20; // for 50 mb devices this will be 2.5 mb // for 12 mb devices this is 0.6 mb mCacheSize = desiredSize;// www.j a v a 2 s . c o m mCache = new LruCache<CacheKey, Bitmap>(desiredSize) { @Override protected int sizeOf(CacheKey key, Bitmap bitmap) { return bitmap.getRowBytes() * bitmap.getHeight(); } }; }
From source file:com.onedollar.image.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)./* w w w . ja va 2s.c o 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.hasJellyBean()) { return bitmap.getByteCount(); } if (Utils.hasHoneycombMR1()) { return bitmap.getByteCount(); } // Pre HC-MR1 return bitmap.getRowBytes() * bitmap.getHeight(); }
From source file:me.vijayjaybhay.galleryview.cache.MemoryImageCache.java
/** * Computes number of bytes in bitmap//w w w .j a va2s .c om * @param data Bitmap data * @return number of bytes in bitmap */ @TargetApi(Build.VERSION_CODES.KITKAT) protected 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:com.chatwingsdk.utils.BitmapLruCache.java
@Override @TargetApi(12)// www . j av a 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; } }