当前位置: 代码迷 >> 综合 >> bitmap 和 drawable 转化
  详细解决方案

bitmap 和 drawable 转化

热度:36   发布时间:2023-12-17 15:48:14.0
1   Bitmap 转成  Drawable
Bitmap bm=xxx; //xxx根据你的情况获取


BitmapDrawable bd=new BitmapDrawable(bm);
因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。
  2   R.drawable.ic_launcher转Bitmap
Bitmap bitmap=BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launch);
mImageView.setImageDrawable(getResources().getDrawable(R.drawable.right)

  3  Drawable 转成 Bitmap
BitmapDrawable bd=(BitmapDrawable)drawable;

Bitmap bitmap=bd.getBitmap();


String fileName = "/data/data/com.test/aa.png; 
Bitmap bm = BitmapFactory.decodeFile(fileName); 
iv.setImageBitmap(bm); 


  相关解决方案