Output stream question

  • Thread starter Thread starter Ivan Demkovitch
  • Start date Start date
I

Ivan Demkovitch

Hi!

I'm using output stream to output image to webpage.

//Move array to response stream.
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(arrBt, 0, arrBt.Length);
Response.End();


But sometime's I want to output link to image instead of byte array.
How do I do this????

ex. //Just pass file name to response...
Response.ContentType = "text/html";
Response.OutputStream.Write((byte[])ScaledImageWebPath, 0,
(int)ScaledImageWebPath.Length);
Response.End();

(example above is not working - cannot convert string to array)
 
Not sure how you can do it.
It all depends on how you are using this aspx in the HTML.
if it's <img src="my.aspx"> then you must output the binary data with the
ContentType "image/jpeg".

My guess the second will not work since browser is expecting the binary data
for image.

My guess you could save the image to the hard drive and then send an
Redirect to that image.
so browser will go and grab that image in response to <img src="my.aspx">



George.
 
George,

You right, I use:
<img src="my.aspx">

What do you mean by redirect? Could you give me a sample of code I use in
my.aspx to make it work?

Thanks,
Ivan

George Ter-Saakov said:
Not sure how you can do it.
It all depends on how you are using this aspx in the HTML.
if it's <img src="my.aspx"> then you must output the binary data with the
ContentType "image/jpeg".

My guess the second will not work since browser is expecting the binary data
for image.

My guess you could save the image to the hard drive and then send an
Redirect to that image.
so browser will go and grab that image in response to <img src="my.aspx">



George.



Ivan Demkovitch said:
Hi!

I'm using output stream to output image to webpage.

//Move array to response stream.
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(arrBt, 0, arrBt.Length);
Response.End();


But sometime's I want to output link to image instead of byte array.
How do I do this????

ex. //Just pass file name to response...
Response.ContentType = "text/html";
Response.OutputStream.Write((byte[])ScaledImageWebPath, 0,
(int)ScaledImageWebPath.Length);
Response.End();

(example above is not working - cannot convert string to array)
 
You cannot write an image directly to an HTML page. You
can only put links to images in a page.
Normally your img tag would point to a jpg or a gif image file.
In your case you'll want it to point to a special page you've designed
specifically for outputting these images.
For example:
<img src='myimage.aspx' ...>
 
Back
Top