我从 ByteMap
创建了 String
public String StringImage(Bitmap bitmap) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] imageByteArray = byteArrayOutputStream.toByteArray();
String encodeImage = Base64.encodeToString(imageByteArray, Base64.DEFAULT);
return encodeImage;
}
我把它放在了 sql server 上。
从sql server 下载这个没有问题。下载后我想从这个字符串创建 ByteMap
。这意味着我需要解码该字符串并创建 BitMap
,但这对我来说太难了。
我在这里尝试解码字符串并创建位图
String donwloadImage = jsonObject.getString("image");
String encode = Base64.encodeToString(donwloadImage.getBytes(),Base64.DEFAULT);
byte [] bytes = Base64.decode(encode, Base64.DEFAULT);
Bitmap bitmap= BitmapFactory.decodeByteArray(bytes,0,bytes.length);
最佳答案
像这样将 Base64 字符串转换为位图 -
byte[] decodeByte = Base64.decode(encodeImage, Base64.DEFAULT);
Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodeByte, 0, decodeByte.length);
关于java - 如何在 android studio 中使用 BASE64 解压缩图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56826832/