One thought on “How to convert a byte array to image in asp.net

  1. 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";
    }
    }

Comments are closed.