0

I have a table that stores images as byte arrays. I iterate through the table rows and retrieve the byte array as follows

byte[] imgArray = (byte[])row[0];

Where row[0] is the varbinary(MAX) column value. I did try something like

MemoryStream ms = new MemoryStream(imgArray);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

My question is how do I display the img object on my asp.net page?

I need to do this programmatically because the rows and the pictures will change real time.

crthompson
  • 15,653
  • 6
  • 58
  • 80
WackStr
  • 188
  • 1
  • 2
  • 11
  • Define real time? At time of page render or will they change even after the page has rendered? – Lloyd Jan 15 '14 at 18:47
  • 1
    Here's the technique: http://stackoverflow.com/a/14935888/394007 ... enjoy! – Dave Clausen Jan 15 '14 at 18:48
  • 1
    Try using the http response as in http://stackoverflow.com/questions/5629251/c-sharp-outputting-image-to-response-output-stream-giving-gdi-error. – cubitouch Jan 15 '14 at 18:48
  • You could directly embed the image bytes in the page itself (requires encoding). Or make a page that outputs only the raw bytes of the image and call it from a link in another page. ie: ``. –  Jan 15 '14 at 18:56

1 Answers1

1

you need to write the image buffer to the response stream.

Each image must be requested separately by your browser. you cannot serve both the page html and the images on the same request.

I suggest you to create an handler that will serve the image dynamicly.

see here for more details on how to write each image buffer to the response stream..

the client will have to request the images one by one from a handler you need to create...

Community
  • 1
  • 1
AMember
  • 3,037
  • 2
  • 33
  • 64
  • 1
    Actually... you **can** serve image and page at the same time: http://rifers.org/blogs/gbevin/2005/4/11/embedding_images_inside_html But it's certainly not recommended in most cases. –  Jan 15 '14 at 18:59