Drawable、Bitmap、byte[]之间的转换
来源:互联网 发布:淘宝企业店铺扣点吗 编辑:程序博客网 时间:2024/05/18 04:58
1、Drawable → Bitmap
Java代码 收藏代码
public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
//canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
2、从资源中获取Bitmap
Java代码 收藏代码
Resources res=getResources();
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);
3、Bitmap → byte[]
Java代码 收藏代码
private byte[] Bitmap2Bytes(Bitmap bm){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
4、 byte[] → Bitmap
Java代码 收藏代码
private Bitmap Bytes2Bimap(byte[] b){
if(b.length!=0){
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
else {
return null;
}
}
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换 (转)
- Drawable、Bitmap、byte[]之间的转换 (转)
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换问题
- Drawable, Bitmap, byte[]之间的转换
- Drawable、Bitmap和byte[]之间的转换
- windows7上安装matlab出现的error starting desktop问题
- sqlmap.xml 中的 添加,修改,刪除(含批量修改、刪除)(编号:20110616A1820)
- 一段有用的谷歌地图使用代码
- 主题不能添加URL连接的解决办法
- 华章IT图书书讯(2011年第6期)
- Drawable、Bitmap、byte[]之间的转换
- 59款很酷的jQuery幻灯片演示和下载
- int av_dup_packet(AVPacket *pkt)
- 非常流行的十款jQuery插件推荐
- error C2065: CoInitializeEx' : undeclared identifier 解决方法
- mysql -error 1005 (errno:150)
- 详解Silverlight和WPF互相扩展(转载)
- CAD二次开发之“添加对象到模型空间”
- Java关于日期的自编的类