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);
原文地址:https://www.cnblogs.com/dcxz/p/3799214.html