I am trying to display an image which is fetched from the database as a binary stream, on the web form. Can you shed some light on this!
I am working on a project where users have profiles, and every user have their own profile picture displayed in the home page. THis picture comes from the database.
here is the code i have used to get the stream !
TestDBDataContext context1 = new TestDBDataContext();
var r = (from a in context1.ImageTables where a.Id == 8 select a).First();
MemoryStream stream = new MemoryStream(r.FileImage.ToArray());
thanks
Base64 encode your binary and insert in an image tag as follows (change the mimetype to suit):
<img src="data:image/gif;base64,BASE64 ENCODED BINARY HERE">
This is how you would do it, but I would not do this as some browsers cannot handle it (IE6). You are better off saving to a file first and doing it the conventional way.
What I've done in the past is set the image url to an aspx page, like so:
<img src="getLogo.aspx" alt="Logo" />
Then, in the code-behind for getLogo.aspx, I've done the following:
Response.BinaryWrite( imageData );
Response.ContentType = "image/gif";
Where imageData
is your image as a byte array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With