码迷,mamicode.com
首页 > 移动开发 > 详细

android 将图片通过base64转换为String 将图片String转换为Bitmap

时间:2014-06-24 09:35:04      阅读:503      评论:0      收藏:0      [点我收藏+]

标签:android   style   class   blog   code   color   

1.Bitmap转换为图片字符串

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

//该方法用来压缩图片,第一个参数为图片格式,第二个参数为截取图片的保留率,如当前为90,则保留之前图片90%的区域
bitmap.compress(Bitmap.CompressFormat.JPEG,90,outputStream );

byte[] imagebyte = outputStream.toByteArray();

//得到图片的String
String imageStr = Base64.encode(imagebyte);

2.将图片String转换为Bitmap

//设str为图片的字符串
byte[] imageByte = Base64.decode(str,Base64.DEFAULT);

Bitmap bitmap = BitmapFactory.decodeByteArray(imageByte,0,imageByte.length);

 

android 将图片通过base64转换为String 将图片String转换为Bitmap,布布扣,bubuko.com

android 将图片通过base64转换为String 将图片String转换为Bitmap

标签:android   style   class   blog   code   color   

原文地址:http://www.cnblogs.com/dcxz/p/3799214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!