没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
1页
Android Drawable和Bitmap的转换实例详解 通常我们需要通过代码去设置图片,就需要设置图片Bitmap和Drawable的转换,下面整理了几种方式 一、Bitmap转Drawable Bitmap bm=xxx; //xxx根据你的情况获取 BitmapDrawable bd=new BitmapDrawable(bm);//因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。 二、 Drawable转Bitmap Drawable d=xxx; //xxx根据自己的情况获取drawable BitmapDrawable bd = (Bit
资源推荐
资源详情
资源评论
Android Drawable和和Bitmap的转换实例详解的转换实例详解
Android Drawable和和Bitmap的转换实例详解的转换实例详解
通常我们需要通过代码去设置图片,就需要设置图片Bitmap和Drawable的转换,下面整理了几种方式
一、一、Bitmap转转Drawable
Bitmap bm=xxx; //xxx根据你的情况获取
BitmapDrawable bd=new BitmapDrawable(bm);//因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。
二、二、 Drawable转转Bitmap
Drawable d=xxx; //xxx根据自己的情况获取drawable
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
//最终bm就是我们需要的Bitmap对象了。
从资源中获取从资源中获取Bitmap
public static Bitmap getBitmapFromResources(Activity act, int resId) {
Resources res = act.getResources();
return BitmapFactory.decodeResource(res, resId);
}
byte[] → Bitmap
public static Bitmap convertBytes2Bimap(byte[] b) {
if (b.length == 0) {
return null;
}
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
// Bitmap → byte[]
public static byte[] convertBitmap2Bytes(Bitmap bm) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
只是很简单代码片段,还是很容易懂得
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章您可能感兴趣的文章:Android中一种巧妙的drawable.xml替代方案分享Android RippleDrawable 水波纹/涟漪效果的实现
Android自定义Drawable之在Drawable中部指定透明区域方法示例浅谈Android中Drawable使用知识总结Android开发基于
Drawable实现圆角矩形的方法Android自定义Drawable实现圆角效果Android Bitmap和Drawable的对比Android
DrawableTextView图片文字居中显示实例Android Drawable必备知识小结Android drawable微技巧,你不知道的drawable细节
资源评论
weixin_38731226
- 粉丝: 6
- 资源: 927
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功