Convert base64 string to image using javascript

I am developing a titanium application. I need to convert a base64 string that I get from JSON to image.

Your help will be greatly appreciated.

+5
source share
2 answers

You can simply create an element imgand modify it srcwith the necessary data:

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

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

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

This will convert the base64 string to blob, which can be used in ImageView.

+3
source

All Articles