2

How to render JPEG/PNG file data contained in Javascript variable? Is it possible ? What javascript libraries needed ? Browser in use is FF / IE.

Thanks

4
  • 1
    How could a JPEG/PNG image be contained in a javascript variable? Is it Base64 encoded? Commented Mar 23, 2010 at 10:23
  • Not Base64 Encoded, it's in binary format. Commented Mar 23, 2010 at 10:28
  • I get the binary data format from Flash Player in the page, transferred via ExternalInterface. Commented Mar 23, 2010 at 10:30
  • Please note that the Data schema may cause some issues with IE6+. In Particular you will have a mixed content warning if using HTTPS Commented Oct 31, 2011 at 13:32

1 Answer 1

2

Modern browsers support inline images. So you could convert the binary data to a base64 encoded string and then append it to the DOM:

var img = document.createElement('img');
img.src = 'data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7';
img.width = '16';
img.height = '14';
document.body.appendChild(img);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.