BitMap、Drawable、inputStream及byte[] 互转
2014-01-10 15:44
169 查看
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);
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);
相关文章推荐
- Zookeeper 集群搭建
- Flex日志详解
- qt 静态库中貌似不能使用静态属性
- Android.mk文件中各字段的含义
- facebook chat api 使用
- Notepad++ 配置java编译环境
- 我与C++山盟海誓
- Android使用AttributeSet自定义控件的方法
- random_shuffle (stl算法)打乱顺序
- bash_profile和.bashrc的什么区别
- Hello Point——WebGL
- C#中如何格式化对齐输出中英文混合字符串
- iPhone推送功能的C语言实现
- mysql 库的导入与导出
- ios KVC(NSKeyValueCoding)用法
- 图像处理之特征值和特征向量的意义
- ActionContextCleanUp过滤器的作用
- 个人总结网络管理系统的管理运维遇到的问题
- Linux下Mongodb安装,命令行操作和sql语句
- 事务隔离级别-实验