ContactImageCache.java 文件源码

java
阅读 15 收藏 0 点赞 0 评论 0

项目:android-giftwise 作者:
protected void initBitmapCache() {
    Log.i(LOG_TAG, "Initialize bitmap cache");

    // Get max available VM memory, exceeding this amount will throw an
    // OutOfMemory exception. Stored in kilobytes as LruCache takes an
    // int in its constructor.
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 8;

    mImageCache = new LruCache<String, RoundedBitmapDrawable>(cacheSize) {
        @Override
        protected int sizeOf(String key, RoundedBitmapDrawable drawable) {
            // The cache size will be measured in kilobytes rather than number of items.
            // return bitmap.getByteCount() / 1024;
            Bitmap bitmap = drawable.getBitmap();
            return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024;
        }
    };
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号