BitMap、Drawable、InputStream、Byte[]互换
来源:互联网 发布:js cookie大小 编辑:程序博客网 时间:2024/05/18 18:21
该方法主要是Bitmap、Drawable、InputStream、Byte[]之间的互相转换.
/** * Bitmap 转换为 InputStream * @param bitmap * @return */ public InputStream bitmapToInputStream(Bitmap bitmap){ InputStream is; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); is = new ByteArrayInputStream(baos .toByteArray()); return is; } /** * Bitmap 转换为 byte[] * @param is * @return */ public byte[] bitmapToByteArray(InputStream is){ byte[] data; Bitmap defaultIcon = BitmapFactory.decodeStream(is); ByteArrayOutputStream stream = new ByteArrayOutputStream(); defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream); data = stream.toByteArray(); return data; } /** * Drawable 转换为 byte[] * @param defaultIcon * @return */ public byte[] drawableToByteArray(Bitmap defaultIcon){ byte[] data; Drawable d = null; // the drawable (Captain Obvious, to the rescue!!!) Bitmap bitmap = ((BitmapDrawable)d).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream); data = stream.toByteArray(); return data; } /** * byte 转换为 Bitmap * @param bitmapdata * @return */ public Bitmap byteArrayToBitmap(byte[] bitmapdata){ Bitmap bitmap =BitmapFactory.decodeByteArray(bitmapdata, 0,bitmapdata.length); return bitmap; }
1 0
- BitMap、Drawable、InputStream、Byte[]互换
- Drawable /Bitmap、String/InputStream、Bitmap/byte[]互转
- Drawable /Bitmap、String/InputStream、Bitmap/byte[]互转
- BitMap、Drawable、inputStream及byte[] 互转
- BitMap、Drawable、inputStream及byte[] 互转
- BitMap、Drawable、inputStream及byte[] 互转
- BitMap、Drawable、inputStream及byte[] 互转
- BitMap、Drawable、inputStream及byte[] 互转
- Android中Bitmap byte[] Drawable InputStream 转化
- BitMap、Drawable、inputStream及byte[] 互转
- android BitMap、Drawable、inputStream及byte[] 互转
- BitMap、Drawable、inputStream及byte[] 互转
- Android Bitmap Drawable byte[] InputStream 相互转换
- Android中Bitmap、Drawable、byte[]互换
- Drawable、Bitmap、byte[]之间的转换 Bitmap转换成InputStream。
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
- live555—VS2010/VS2013 下live555编译、使用及测试
- ASP.net和EasyUI后台管理系统
- 集群和分布式的区别
- HashMap
- HM编码器代码阅读(2)——框架以及主要流程
- BitMap、Drawable、InputStream、Byte[]互换
- Tomcat结构分析
- [PHP实例] PHP多文件上传实现
- 剑指offer系列之33:第一个只出现一次的字符
- 轨迹记忆
- lightoj1018 - Brush (IV)【状压dp】
- Java 多线程处理任务的封装
- 每天编程小题目(oneDay):求每个月兔子总数
- VirtualBOX 虚拟机安装 OS X 10.9 Mavericks 及 Xcode 5,本人X220亲测