Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert base64 string to image with javascript

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.

like image 283
Mayoor Avatar asked Feb 24 '12 10:02

Mayoor


2 Answers

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

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />
like image 113
ldiqual Avatar answered Nov 10 '22 21:11

ldiqual


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.

like image 38
Josiah Hester Avatar answered Nov 10 '22 22:11

Josiah Hester