gpt4 book ai didi

java - 如何在 android studio 中使用 BASE64 解压缩图像

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:17 25 4
gpt4 key购买 nike

我从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com