I have a byte array representing an image. I want to display the image stored in that byte array in an aspx page. Can I do it using an image or imagemap control?
John from Kentlands
I have a byte array representing an image. I want to display the image stored in that byte array in an aspx page. Can I do it using an image or imagemap control?
John from Kentlands
Comments are closed.
Hello John
If you look at how normal images are served in a web page – you will find that the filename is referenced in the markup, and the browser sends a separate request to the server for that file.
The same principle applies here, except instead of referencing a static image file, you would want to reference an ASP.NET handler that serves the bytes of the image:
< img src="/imagehandler.ashx" / >
The code of the handler would look something like this:
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.OutputStream.Write(imageData, 0, imageData.Length);
context.Response.ContentType = "image/JPEG";
}
}