Resource ->drawable
Drawable d=this.getResources().getDrawable(R.drawable.ic_launcher);
drawable->Bitmap
public Bitmap bitmap(Drawable d){
//获取drawable的宽和高
int width=d.getIntrinsicWidth();
int height=d.getIntrinsicHeight();
//取drawable的格式
<pre name="code" class="html">Bitmap.Config config = d.getOpacity() != PixelFormat.OPAQUE ?Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565;
Bitmap bitmap=Bitmap.createBitmap(width, height, config);
Canvas canvas=new Canvas(bitmap);
d.setBounds(0, 0, width, height);
d.draw(canvas);
return bitmap;
}
Bitmap->drawable
//将assets文件中资源取出,并将图片从bitmap转换成drawable格式
public static Drawable getDrawableFromAssetFile(Context context,String fileName){
Bitmap image = null;
BitmapDrawable drawable=null;
try{
AssetManager am = context.getAssets();
InputStream is = am.open(fileName);
image = BitmapFactory.decodeStream(is);
drawable= new BitmapDrawable(context.getResources(), image);
is.close();
}catch(Exception e){
}
return drawable;
}
//Bitmap drawable 转换 和byte【】