-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
赌徒
authored and
赌徒
committed
Feb 21, 2020
1 parent
805248a
commit 4fb2e42
Showing
2 changed files
with
45 additions
and
24 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
ImageloaderUtils/src/main/java/com/junl/utils/ImageloaderUtils/ImageCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.junl.utils.ImageloaderUtils; | ||
|
||
import android.graphics.Bitmap; | ||
import android.util.LruCache; | ||
|
||
public class ImageCache { | ||
LruCache<String, Bitmap> mImageCache; | ||
|
||
public ImageCache() { | ||
initImageCache(); | ||
} | ||
|
||
private void initImageCache() { | ||
//计算可使用的最大内存 | ||
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); | ||
//取四分之一的可用内存作为缓存 | ||
final int cacheSize = maxMemory / 4; | ||
|
||
mImageCache = new LruCache<String, Bitmap>(cacheSize) { | ||
@Override | ||
protected int sizeOf(String key, Bitmap bitmap) { | ||
return bitmap.getRowBytes() * bitmap.getHeight() / 1024; | ||
} | ||
}; | ||
} | ||
|
||
public void put(String url, Bitmap bitmap) { | ||
mImageCache.put(url, bitmap); | ||
} | ||
|
||
public Bitmap get(String url) { | ||
return mImageCache.get(url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters