Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi Everyone,

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.

VB
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... !!
Posted
Comments
Sunasara Imdadhusen 25-Oct-10 5:38am    
I think you should provide full privilege of folder

PS:This below code is in C#.
Please do the following steps to resolve it.

Step1: Take 1 new Page Test.aspx

Code behind Test1.aspx.cs
C#
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
C#
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:
 
Share this answer
 
Comments
Sifar - 0 25-Oct-10 8:06am    
It worked !!
I used as follow...

context.Response.Write("<img src=""Test1.aspx?PATH=path"" alt=""ASPX IMAGE"">")

Thank you....

----------------------

@Everyone, if anyone knows how to achieve this without adding ASPX page then it would be really appreciated.
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.
 
Share this answer
 
Comments
NMehta83 25-Oct-10 6:41am    
If you remove this line 'context.Response.ContentType = "image/jpeg"' then also it will not show you the plain/html text. I also tried it.
Sifar - 0 25-Oct-10 6:44am    
Yes, I had also tried this.... removing "image/jpeg". No Use. :(
Rod Kemp 25-Oct-10 7:45am    
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900