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


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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM