2013-03-01 56 views
0

从SoftReference的retrive位图,我把我的位图到HashMap中为:无法在Android的

HashMap<String, SoftReference<Bitmap>> imageMap = new HashMap<String, SoftReference<Bitmap>>(); 

.... 

bitmap = BitmapFactory.decodeStream(inputstream); 

imageMap.put(String.valueOf(i), new SoftReference<Bitmap>(bitmap)); 

而且我每次递增它,我也得到位。

我retrive位图由:

SoftReference<Bitmap> setValue = imageMap.get(String.valueOf(count)); 

Bitmap bitmap=setValue.get(); 

我递增。但我得到的位图特定计数我们only.How可以从HashMap的每一个位图计数每一次?

回答

0

SoftReference不会保留保留在内存中的对象,所以如果您为位图接收到空值,则应该再次将其解码并放入HashMap中。

+0

解码需要很长时间。这就是为什么我在解码器本身解码所有图像的原因。我能做些什么来避免这种时间延迟? – 2013-03-01 07:07:51

+0

它实际上取决于您使用图像的方式。你有没有检查http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html?这种方式可能更适用,因为SoftReference可能被清除得太快。 – sandrstar 2013-03-01 07:16:58