【发布时间】:2016-04-04 07:20:13
【问题描述】:
我有 SVG 文件编码为 base64,我想用 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," or "data:image/jpeg;base64,) decodedByte 也总是返回 null
- base64 字符串是正确的(它在 HTML 和其他 base64 中运行良好 在线工具)
【问题讨论】:
-
查看stackoverflow.com/questions/3889882/svg-support-on-android了解如何在Android上使用SVG