3 回答

12345678_0001
TA贡献1802条经验 获得超5个赞
不知道你问题的哪个部分?
服务器端如何把图片转换成base64字符串?
String filePath = ".......";
Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
selectedImage.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
String strBase64=Base64.encodeToString(byteArray, 0);
//下面你只要把这个字符串当成api的返回值,返回给android端就好了
下面是android上如何把base64的字符串转换成图片(ImageView默认不能显示base64)
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
添加回答
举报
0/150
提交
取消