代码改变世界

android 最省内存的方式读取本地资源的图片

2011-07-22 16:49  雪夜&流星  阅读(1246)  评论(2编辑  收藏  举报
获取资源文件:
public
static Bitmap readBitMap(Context context, int resId){
BitmapFactory.Options opt
= new BitmapFactory.Options();
opt.inPreferredConfig
= Bitmap.Config.RGB_565;
opt.inPurgeable
= true;
opt.inInputShareable
= true;
//获取资源图片
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is,null,opt);
}
回收bitmap
public static void recycle(Bitmap bmp){

if(bmp!=null&&!bmp.isRecycled() )
{
bmp.recycle();
//回收图片所占的内存
System.gc(); //提醒系统及时回收
}
}