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:org.videolan.vlc.util.BitmapCache.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private BitmapCache() {

    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final ActivityManager am = ((ActivityManager) VLCApplication.getAppContext()
            .getSystemService(Context.ACTIVITY_SERVICE));
    final int memClass = AndroidUtil.isHoneycombOrLater() ? am.getLargeMemoryClass() : am.getMemoryClass();

    // Use 1/5th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 5;

    Log.d(TAG, "LRUCache size sets to " + cacheSize);

    mMemCache = new LruCache<String, Bitmap>(cacheSize) {

        @Override/*from w w  w .j a v  a 2  s. co  m*/
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }

    };
}

From source file:com.nf2m.util.ImageCache.java

/**
 * Get the size in bytes of UriObserver bitmap in UriObserver 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  .ja  v a 2s. c o  m
 * @return size in bytes
 */
@TargetApi(VERSION_CODES.KITKAT)
private static int getBitmapSize(@NonNull 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.amachikhin.vkmachikhin.utils.image_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).
 *
 * @param value//from www  . j ava 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 >= VERSION_CODES.HONEYCOMB_MR1) {
        return bitmap.getByteCount();
    }

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

From source file:com.ibuildapp.romanblack.CataloguePlugin.imageloader.Plugin.java

private Plugin() {
    final int CORES = Runtime.getRuntime().availableProcessors();
    final int THREAD_POOL_SIZE_NETWORK = CORES + 1;
    final int THREAD_POOL_SIZE_NETWORK_MAX = CORES * 2 + 1;
    final long KEEP_ALIVE_VALUE = 1;
    final TimeUnit KEEP_ALIVE_VALUE_TIME_UNIT = TimeUnit.SECONDS;
    final int CACHE_BITMAP_SIZE = (int) (Runtime.getRuntime().maxMemory() / 8192f);

    cacheBitmap = new LruCache<String, Bitmap>(CACHE_BITMAP_SIZE) {
        @Override//  w ww . j  a  va2s . c o  m
        protected int sizeOf(String key, Bitmap bitmap) {
            return (int) ((bitmap.getRowBytes() * bitmap.getHeight()) / 1024f);
        }
    };

    queueNetwork = new LinkedBlockingQueue<>();
    queueLocal = new LinkedBlockingQueue<>();

    threadPoolNetwork = new ThreadPoolExecutor(THREAD_POOL_SIZE_NETWORK, THREAD_POOL_SIZE_NETWORK_MAX,
            KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT, queueNetwork);
    threadPoolLocal = new ThreadPoolExecutor(CORES, CORES, KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT,
            queueLocal);
}

From source file:com.ibuildapp.ZopimChatPlugin.core.Core.java

Core() {
    final int CORES = Runtime.getRuntime().availableProcessors();
    final int THREAD_POOL_SIZE_NETWORK = CORES + 1;
    final int THREAD_POOL_SIZE_NETWORK_MAX = CORES * 2 + 1;
    final long KEEP_ALIVE_VALUE = 1;
    final TimeUnit KEEP_ALIVE_VALUE_TIME_UNIT = TimeUnit.SECONDS;
    final int CACHE_BITMAP_SIZE = (int) (Runtime.getRuntime().maxMemory() / 8192f);

    cacheBitmap = new LruCache<String, Bitmap>(CACHE_BITMAP_SIZE) {
        @Override/*from   www. j  av  a 2 s .  co m*/
        protected int sizeOf(String key, Bitmap bitmap) {
            return (int) ((bitmap.getRowBytes() * bitmap.getHeight()) / 1024f);
        }
    };

    queueNetwork = new LinkedBlockingQueue<>();
    queueLocal = new LinkedBlockingQueue<>();

    threadPoolNetwork = new ThreadPoolExecutor(THREAD_POOL_SIZE_NETWORK, THREAD_POOL_SIZE_NETWORK_MAX,
            KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT, queueNetwork);
    threadPoolLocal = new ThreadPoolExecutor(CORES, CORES, KEEP_ALIVE_VALUE, KEEP_ALIVE_VALUE_TIME_UNIT,
            queueLocal);
}

From source file:org.montanafoodhub.app.utils.ImageCache.java

public ImageCache() {

    // set the cache to be 1/8 of the total memory (kilobytes)
    int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    int cacheSize = maxMemory / 8;

    Log.w(LogTag, "Cache Size: " + cacheSize);

    _cache = new LruCache<String, Bitmap>(cacheSize) {
        @Override//from  w  ww .jav a  2 s . c o m
        protected int sizeOf(String key, Bitmap bitmap) {
            // todo bitmap.getAllocationByteCount()
            return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024;
        }
    };
}

From source file:com.jasper.image.imagemanager.imagehelper.imageEngine.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 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 (VersionUtils.hasKitKat()) {
        // return bitmap.getAllocationByteCount();
        return bitmap.getByteCount();
    }

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

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

From source file:org.lucasr.smoothie.samples.gallery.GalleryLoader.java

public GalleryLoader(Context context) {
    mContext = context;//from  w w  w  .ja va 2  s.  c o m

    int maxSize = (int) (Runtime.getRuntime().maxMemory() * 0.4f);
    mMemCache = new LruCache<Long, Bitmap>(maxSize) {
        @Override
        protected int sizeOf(Long id, Bitmap bitmap) {
            return bitmap.getRowBytes() * bitmap.getHeight();
        }
    };
}

From source file:com.androidpi.bricks.gallery.lru.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 w w  w  .j  a  va  2  s .c  o  m*/
 *
 * @param value
 * @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 (AppUtil.hasKitKat()) {
        return bitmap.getAllocationByteCount();
    }

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

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

From source file:com.stargame.ad.util.cache.image.AbImageBaseCache.java

/**
 * ./* w ww . ja  v  a 2s .c  o  m*/
 */
public AbImageBaseCache() {
    super();
    int maxSize = AppConfig.MAX_CACHE_SIZE_INBYTES;
    mCache = new LruCache<String, Bitmap>(maxSize) {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            try {
                return value.getRowBytes() * value.getHeight();
            } catch (Exception e) {
                // e.printStackTrace();
                return value.getByteCount();
            }
        }
    };
}