Putting and Image into the OutputStream

Last post 06-04-2009 4:39 PM by AsaLyon. 2 replies.

Sort Posts:

  • Putting and Image into the OutputStream

    06-04-2009, 2:38 PM
    • Member
      25 point Member
    • AsaLyon
    • Member since 09-19-2005, 10:15 PM
    • Posts 15

    I am building an image in memory using GDI+ and trying to put it into the OutputStream on a page that has many other controls. When I use the following:

    imgBmp.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg)

    The image is the only thing that shows on the page. All other controls in the page do not show up. How do I place the image into the OutputStream along with all the other controls.

     Any Help would be appreciated!

     

    Filed under:
  • Re: Putting and Image into the OutputStream

    06-04-2009, 4:26 PM
    Answer
    • Contributor
      4,008 point Contributor
    • Matt-dot-net
    • Member since 06-09-2007, 4:00 PM
    • Kentucky
    • Posts 772

    You have to understand how HTTP works to understand your problem.  Consider these points.

    1. HTTP uses a stateless request/response pair.  One response for one request.
    2. Each response has a content-type header which tells the client what type of content is in this response

    Given number 2 you should understand your problem.  You are talking about a Response with multiple content types.  This is not supported by HTTP.  If you are still confused and asking yourself, how do typical web pages have images and text content, refer to points 1 and 2 above.  When a browser sees, within the text/html content of a response, "<img src='image.jpg' />" it knows to issue another HTTP request for the URL http://..../image.jpg.  The server then responds with a new content type (img/jpeg).  So your browser issues multiple requests and reads multiple responses.

    Long story short.  You need either an HTTPHandler (the best practice way) to handle your images, or just a separate .aspx page that is meant to serve images.  You have already suceeded in responding with an image, so just move that code to your image.aspx page.  Use a query string parameter (or session) to determine which image to send.  Then on your original page use an HTML image tag with src="ImagePage.aspx" mce_src="ImagePage.aspx".

    Hope this helps.

  • Re: Putting and Image into the OutputStream

    06-04-2009, 4:39 PM
    • Member
      25 point Member
    • AsaLyon
    • Member since 09-19-2005, 10:15 PM
    • Posts 15

    Thanks so much for the explanation!

     

    Gives me a better understanding of the flow of things.

     

     

     

Page 1 of 1 (3 items)