tags:

views:

103

answers:

1

I create a binary input stream using some js trickery which contains compressed image data like jpeg or gif. I want to decode and display this data either using imgITools::decodeImageData or some other way but couldn't find a way yet. Where should I start?

A: 

The easiest way is to read the image data into a string, base64 encode the string, then turn that into a data: URL and set that as the src of your image. Unfortunately stackoverflow won't let me create a live data: link, but it would look like this:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAMklEQVRIx2NgGAWjYBQMFXAFDRMrR5GF/6H4CglyoxaOWjhq4aiFg7hoGwWjYBTQDgAAy8VWOfRR6fkAAAAASUVORK5CYII="
Neil