如何从 BASE64 字符串 reciveb dy JSON 在 ImageView 中设置图像
How to set image in ImageView from BASE64 string reciveb dy JSON
我有类似的东西:
JSONArray Icons = new JSONArray();
在 AsyncTask 中,我正在从 Flask 服务器接收 BASE64 中的图像:
Icons = (JSONArray) result.get("Icons");
现在我需要使用存储在 BASE64 JSONArray 中的图像更新 ImageView。它应该是这样的:
imageView.setImageBitmap(Icons.get(i)...)
您可以解码 base64
图像并像这样在 imageView 中设置:
byte[] decodedString = Base64.decode(strBase64, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
image.setImageBitmap(decodedByte);
此外,请在设置之前检查您是否收到有效的 base64 字符串。
我有类似的东西:
JSONArray Icons = new JSONArray();
在 AsyncTask 中,我正在从 Flask 服务器接收 BASE64 中的图像:
Icons = (JSONArray) result.get("Icons");
现在我需要使用存储在 BASE64 JSONArray 中的图像更新 ImageView。它应该是这样的:
imageView.setImageBitmap(Icons.get(i)...)
您可以解码 base64
图像并像这样在 imageView 中设置:
byte[] decodedString = Base64.decode(strBase64, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
image.setImageBitmap(decodedByte);
此外,请在设置之前检查您是否收到有效的 base64 字符串。