Reputation: 6710
Here is how my code is:
page.aspx:
<asp:Image ID="Image1" runat="server" />
Code behind:
byte[] IMG = class.readImg(id);
Image1.ImageUrl = "~/page.aspx?ID=" + id.ToString();
Context.Response.ContentType = "image/jpg";
Context.Response.BinaryWrite(IMG);
Whith this code, the only thing that shows in page.aspx is the image read.
Upvotes: 0
Views: 5919
Reputation: 21
NO need to use a HttpHandler
just use the following code retrieve data from SQL Server into DataTable.
Into .ASPX page
<img runat=server id="logoImg" alt="" src="" />
Into C# Code
byte[] imgArray = (byte[])dTable.Rows[0][8];
logoImg.Src = "data:image/png;base64," + Convert.ToBase64String(imgArray);
Upvotes: 2
Reputation: 15252
Here's a solution from a similar, recent question:
Display image from database in ASP.net with C#
You need to use a HttpHandler class to retrieve and write the stream.
Upvotes: 0