我有一个以base64编码的SVG文件,我想用ImageView显示图片。 这是我尝试过的方法:
// imageBase64 is string that represents the SVG image encoded as base64
byte[] decodedString = Base64.decode(imageBase64, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
但是decodedByte始终返回null。
PS:
- 此代码适用于jpeg图像。
- 如果base64字符串包含base64前缀("data:image/svg+xml;base64,"或"data:image/jpeg;base64,"),decodedByte始终返回null。
- base64字符串是正确的(在HTML和其他在线base64工具中运行良好)