Skip to content
Advertisement

How to convert a byte array into an image?

Using Javascript, I’m making an AJAX call to a WCF service, and it is returning a byte array. How can I convert that to an image and display it on the web page?

Advertisement

Answer

I realize this is an old thread, but I managed to do this through an AJAX call on a web service and thought I’d share…

  • I have an image in my page already:

    JavaScript
  • AJAX:

    JavaScript

My ‘GetItemPreview’ code queries a SQL server where I have an image stored as a base64 string and returns that field as the ‘results’:

JavaScript

The magic is in the AJAX call at this line:

JavaScript

Enjoy!

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement