Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming byte[] to Image in ASP.NET C#

Tags:

I have an Image stored in my SQL Server database stored with my User data which I retrieve all at once.

Now I have the byte[] directly on the page I want to show it on. How do I put it in my WebControls.Image? I don't want to have to call an HttpHandler and call the database again.

This obviously just outputs it to the whole page.

            Context.Response.BinaryWrite(user.Picture.ToArray());
like image 777
markoo Avatar asked Aug 28 '09 11:08

markoo


1 Answers

If it is a small image you would output it as base64 encoded data into an image-tag. See here for a similar situation.

But in 99.9% of all situations you would create a HttpHandler that returns the image. It is the easiest and fastest way to do it I think.

like image 94
Rune Grimstad Avatar answered Oct 02 '22 13:10

Rune Grimstad