一、Bitmap与Drawable之间的相互转换(高效方法)
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.loadimage1);
BitmapDrawable bd = new BitmapDrawable(bitmap);
Bitmap bm = bd.getBitmap();
BitmapDrawable是Drawable的子类,把Bitmap或Drawable转换成BitmapDrawable,通过BitmapDrawable转换成要得到的类型。
二、SoftReference<Drawable>用来处理解决大量图片下载内存溢出的问题
1、public Map<String, SoftReference<Drawable>> imageCache = new HashMap<String, SoftReference<Drawable>>();
2、 //如果缓存过就从缓存中取出数据
if (imageCache.containsKey(imageUrl)) {
SoftReference<Drawable> softReference = imageCache.get(imageUrl);
if (softReference.get() != null) {
return softReference.get();//得到缓存中的Drawable
}
}
3、 imageCache.put(imageUrl, new SoftReference<Drawable>(drawable));
三、