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:com.cmgapps.android.util.BitmapCache.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override//from   w ww  .j a v  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.mifashow.tool.image.ImageCache.java

/**
 * Initialize the cache, providing all parameters.
 *
 * @param context The context to use/*from  www.ja va  2  s.c o m*/
 * @param cacheParams The cache parameters to initialize the cache
 */
private void init(Context context, ImageCacheParams cacheParams) {
    final File diskCacheDir = DiskLruCache.getDiskCacheDir(context, cacheParams.uniqueName);

    // Set up disk cache
    if (cacheParams.diskCacheEnabled) {
        mDiskCache = DiskLruCache.openCache(context, diskCacheDir, cacheParams.diskCacheSize);
        mDiskCache.setCompressParams(cacheParams.compressFormat, cacheParams.compressQuality);
        if (cacheParams.clearDiskCacheOnStart) {
            mDiskCache.clearCache();
        }
    }

    // Set up memory cache
    if (cacheParams.memoryCacheEnabled) {
        mMemoryCache = new LruCache<String, Bitmap>(cacheParams.memCacheSize) {
            /**
             * Measure item size in bytes rather than units which is more practical for a bitmap
             * cache
             */
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight();
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
                Log.d("-ImageCache", "MemCache is full:" + this.size() + "/" + this.maxSize());

            }
        };
    }
}

From source file:org.mythdroid.cache.ImageCache.java

/**
 * Add an image to the cache/*ww  w.ja v  a 2  s .  c  o m*/
 * @param key identifier
 * @param value image to cache
 */
public void put(final String key, final Bitmap value) {
    final String k = normalise(key);
    if (memMax == 0 || value.getRowBytes() * value.getHeight() <= memMax)
        memCache.put(k, value);
    if (diskCache != null) {
        synchronized (queue) {
            queue.add(new Runnable() {
                @Override
                public void run() {
                    diskCache.put(k, value);
                }
            });
            queue.notify();
        }
    }
}

From source file:com.zhongyun.viewer.utils.ImageDownloader.java

public ImageDownloader() {
    options.inJustDecodeBounds = false;//  w  ww. j  av a  2 s.c  o  m
    cacheDir = FileUtils.createFile(Constants.LOCAL_CID_ICON_PATH);

    int MAXMEMONRY = (int) (Runtime.getRuntime().maxMemory() / 1024);
    if (null == mMemoryCache) {
        mMemoryCache = new LruCache<String, Bitmap>(MAXMEMONRY / 8) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
                if (oldValue != null && !oldValue.isRecycled()) {
                    oldValue.recycle();
                    oldValue = null;
                }

            }
        };
    }

    if (null == mMemoryCache_sd) {
        mMemoryCache_sd = new LruCache<String, Bitmap>(MAXMEMONRY / 8) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }

            @Override
            protected void entryRemoved(boolean evicted, String key, Bitmap oldValue, Bitmap newValue) {
                if (oldValue != null && !oldValue.isRecycled()) {
                    oldValue.recycle();
                    oldValue = null;
                }

            }
        };
    }
}

From source file:cc.softwarefactory.lokki.android.MainApplication.java

@Override
public void onCreate() {

    Log.e(TAG, "Lokki started component");

    loadSetting();/*from   w  ww  . j a va 2s  .  co  m*/

    locationDisabledPromptShown = false;

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 8;
    avatarCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than number of items.
            return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024;
        }
    };

    String iDontWantToSeeString = PreferenceUtils.getString(this, PreferenceUtils.KEY_I_DONT_WANT_TO_SEE);
    if (!iDontWantToSeeString.isEmpty()) {
        try {
            MainApplication.iDontWantToSee = new JSONObject(iDontWantToSeeString);
        } catch (JSONException e) {
            MainApplication.iDontWantToSee = null;
            Log.e(TAG, e.getMessage());
        }
    } else {
        MainApplication.iDontWantToSee = new JSONObject();
    }
    Log.e(TAG, "MainApplication.iDontWantToSee: " + MainApplication.iDontWantToSee);

    if (DEVELOPER_MODE) {

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());

        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                //.detectLeakedClosableObjects()
                .penaltyLog().penaltyDeath().build());
    }

    super.onCreate();
}

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

/**
 * @param maxSize ???kb//from   w w w . j ava 2 s .  c  o m
 */
@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 {// ww w .j a  v a  2  s  .c om
        return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
    }
}

From source file:com.zion.adapter.CachedImageCursorAdapter.java

public CachedImageCursorAdapter(Context context, Cursor cursor, boolean autoRequery) {
    super(context, cursor, autoRequery);

    this.context = context;

    // Get memory class of this device, exceeding this amount will throw an OutOfMemory exception.
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // Use 1/8th of the available memory for this memory cache.
    this.memoryCache = new LruCache<String, Bitmap>(maxMemory / 8) {
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in bytes rather than number of items.
            return bitmap.getRowBytes() * bitmap.getHeight();
        }//from   ww w . ja v  a2 s  .c o  m
    };
}

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

@Override
protected int sizeOf(String 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 {/*  ww w.  jav  a2 s  . c  o m*/
        return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
    }
}

From source file:com.yanzhenjie.album.task.ImageLocalLoader.java

private ImageLocalLoader() {
    mExecutorService = Executors.newFixedThreadPool(5);

    int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 8);
    mLruCache = new LruCache<String, Bitmap>(maxMemory) {
        @Override/*from  w w  w .jav  a2  s .  c om*/
        protected int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
}