/**
* 以最省内存的方式读取本地资源的图片
* @param context
* @param resId
* @return
*/
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对象转换Drawable.
* @param bitmap 要转化的Bitmap对象
* @return Drawable 转化完成的Drawable对象
*/
public static Drawable bitmapToDrawable(Bitmap bitmap) {
BitmapDrawable mBitmapDrawable = null;
try {
if(bitmap==null){
return null;
}
mBitmapDrawable = new BitmapDrawable(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
return mBitmapDrawable;
}