I have one HTML page, on submitting I am calling a Hanlder (ASHX).
In handler, I am generating an image. That image should not be saved on client/server machine. So I saved the Image in MemoryStream. After that I need to display that image with some detail text.
I could display the Image with Response.BinaryWrite() method.. but when I try to write text with Response.Write() , text does not appear.
Dim ms As MemoryStream = New MemoryStream() BCImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) context.Response.ContentType = " image/jpeg" context.Response.Clear() context.Response.BinaryWrite(ms.ToArray()) context.Response.Write( " <BR> HI <BR>" )
Any ideas... !! protected void Page_Load( object sender, EventArgs e) System.Drawing.Image BCImage = new System.Drawing.Bitmap( @" C:\test.jpg" ); MemoryStream ms = new MemoryStream(); BCImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); Response.ContentType = " image/jpeg" ; Response.Clear(); Response.BinaryWrite(ms.ToArray()); Step2: On your handler page
Image img = new Image(); img.ImageUrl = " ~/Test1.aspx" ; panel1.Controls.Add(img); Response.Write( " <BR> HI <BR>" );
Then it will show you both the things(Image and text/html content)
If this helped you then please Vote and accept as Answer :rose: You have told the browser to expect a image of type jpeg with
VB
context.Response.ContentType = " image/jpeg"
so it is not expecting you to also send plain/html text, so it will either ignore it or maybe lump it in with the image data, either way it will not display it.
Removing the ContentType has no effect because browsers can display jpg files internally so the first thing a browser sees is a jpg file header and the assumption is made that all data that follows is image data, if you were trying to push a zip or a pdf file out with BinaryWrite and no ContentType you would normally see something very different.
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •