[urgent] how to output image in place

  • Thread starter Thread starter pei_world
  • Start date Start date
P

pei_world

in asp or php, we can use inner output command to print out text or other
thing inside out web page.
I want to know how to do this in asp.net.
I know user control with placesholder can do, but if I want to generate a
image and output to client directly, then I cann't set the imageurl. I want
to know if there is anyway that I can display this image to user in some
place of my web page.

thanks
 
Use the HTTP header to define the content type.

The following sample returns a picture :

Response.ContentType = "image/jpeg";

Bitmap bmp;

// Create your image here

MemoryStream memStream = new MemoryStream();
bmp.Save(memStream, ImageFormat.Jpeg);
memStream.WriteTo(Response.OutputStream);
 
yes, I can display it. but I have a table with other content as well, I just
want this image to be display in one of the cell in that table, not only
display the image.
 
you can't do that...this isn't a limitation of ASP.Net, it's a limitation of
HTTP. Images must be served in a separate HTTP response - you can't package
normal html/text with binary data - it just don't work that way. What you
need to do is:

<table>
<tr>
<td>Some Text</td>
<td><asp:SomeASPNet.../></td>
<td><img src="dynamicImage.aspx"></td>
</tr>
</table>

When the browser sees an <img tag it does a new request for the resource
(dynamicImage.aspx). If dynamicImage.aspx returns binary data with the
right content-type (as was suggested, everything works).

Please refrain from posting the same question 3 times while at the same time
baiting people into helping you by saying if it can't be done than ASP.net
sucks....especially when it's your own lack of understanding which is the
bottleneck.

Karl
 
Actually, you can assign Server Control Image's ImageUrl
not only in degign time but also in run time.

Elton Wang
(e-mail address removed)
 
Back
Top