convert base64 string to image with javascript

末鹿安然 提交于 2020-01-10 15:36:15

问题


Am developing an application with Titanium. I need to convert base64 string which i would be getting from JSON to an image.

Your help would be greatly appreciated.


回答1:


You can just create an img element and change its src with the required data:

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />



回答2:


For Titanium, you use the built in conversion utility Titanium.Utils.base64decode:

var imageFromBase64 = Titanium.UI.createImageView({
    image : Titanium.Utils.base64decode("iVBORw0KGgoAAAANS..."),
});

This converts a base64 string to a blob, which can be used in an ImageView.



来源:https://stackoverflow.com/questions/9429234/convert-base64-string-to-image-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!