BitMap,inputStream,byte[],Drawable之间的相互转换
来源:互联网 发布:网络渗透基础 编辑:程序博客网 时间:2024/05/16 17:17
在Android开发中,有时候我们会得到一个byte[],但是我们需要的是一个Drawable,或者是一个BitMap,那么我们该如何转换呢?
(1) BitMap to inputStream:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
InputStream isBm = new ByteArrayInputStream(baos .toByteArray());
(2)BitMap to byte[]:
Bitmap defaultIcon = BitmapFactory.decodeStream(in);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
(3)Drawable to byte[]:
Drawable d; // the drawable (Captain Obvious, to the rescue!!!)
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, bitmap);
byte[] bitmapdata = stream.toByteArray();
(4)byte[] to Bitmap :
Bitmap bitmap =BitmapFactory.decodeByteArray(byte[], 0,byte[].length);
- BitMap,inputStream,byte[],Drawable之间的相互转换
- 【Android】Bitmap、InputStream、Drawable、byte[]、Base64之间的相互转换
- Drawable、Bitmap、byte[]之间的转换 Bitmap转换成InputStream。
- Android Bitmap Drawable byte[] InputStream 相互转换
- android 中byte[] bitmap drawable inputstream的相互转换
- android byte[]数组,bitmap,drawable之间的相互转换
- Bitmap与byte、file、Drawable之间的相互转换
- Android Bitmap Drawable byte[] InputStream 相互转换方法
- Bitmap和Drawable之间的相互转换、Bitmap和 byte[] 之间的相互转换、从资源中获取Bitmap
- Drawable、 Bitmap、byte[] 的相互转换
- Drawable,Bitmap,byte[]的相互转换
- Drawable、 Bitmap、byte[] 的相互转换
- Bitmap Byte 和Drawable 的相互转换
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类
- Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】
- 问题 U 杨辉三角形
- 嵌套控件的可见关系记录
- alsa lib和utils交叉编译与移植
- 让网页中图片无法拖动
- CSS鼠标样式
- BitMap,inputStream,byte[],Drawable之间的相互转换
- leetcode No101. Symmetric Tree
- UILabel的有关用法
- Genymotion 安装项目失败,闪退
- DispatcherServlet的认识和解析
- 问题 T 序列求和
- sql语句CASE WHEN 的使用
- LintCode_393 Best Time to Buy and Sell Stock IV
- [ios]启动 EASession 失败 — — EAAccessory 没有Protocol