Render byte[] to image using jQuery Render byte[] to image using jQuery sql-server sql-server

Render byte[] to image using jQuery


Return the byte[] from the webserver with the correct content-type set, that way you should be able to set it as a source for a image tag. Should be the simplest solution.


If you must do it this way, you can insert image data directly into the src attribute using the following syntax:

data:image/<type>;base64,<data>

Replace with the image type (jpg, png, gif) and with your data, encoded in base 64.

However, as decyclone says, the best way to do this would be to create a separate page that only outputs your image data, and sends the appropriate content-type header. Then set the image src to point to that page.


I don't think using jQuery is the right thing to do here. It's a client side thing. JavaScript, to be specific.

Usually, you create a page that writes all these bytes in array using Response.Write() and setting the content-type to jpeg, bmp, etc. depending on image type.