4

I have been trying to load images which are in database(on local phone) .JSON talks to java and gets the byte array which i am encoding as 64 bit data and returns a string array . Now i am trying to parse the json data. I see the array but how do i read it or set it image tag in html . All answers are appreciated

1 Answer 1

11

Use the data:// URI scheme.

For example, if the base64-encoded data is:

iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==

then you'd drop that data into an image's src attribute like so:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

which draws this image:

small red dot

Sign up to request clarification or add additional context in comments.

1 Comment

@David it's especially neat to be able to draw (anything) on a <canvas> and then render it as a regular <img> in the page using canvas.toDataURL().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.