Is there a way to download an image (binary) from a database in sql server and insert it on a page as an image control? I want to add the image to a page when it loads. I can't figure how to do it and I am not sure if it is possible to do.
I've never actually done that, but I'm guessing you're going to have to create some sort of BinaryStream then create a file out of that, then use the BitMap.LoadFromFile() method to load the picture....I'm not actualy sure though.
I found a way to do it. I uploaded all the thousands of images to the DB. Now to show them up, I download the one I need to the server, then just show it on the page. It's fine like this but if anybody would know if it is possible to show the image on a page without copying the file to a drive, it would be nice... thx
You set the image into the HTTP response stream, setting the proper MIME type, of course. Do an internet search for "image response stream".
This question might have been answered sooner if it were posted in the Web Development | ASP.NET forum.
I tried something like that but if you are talking about what I think you are, only the image would be showing in the browser and not the image in a page if you know what I mean. I want to be able to generate the rest of the page not just the image.
Youre right I should've posted this in the .NET forum. :)
Something like this, in the code-behind. This is code that creates an in-memory graphic, but you could just as well retrieve the image from a database:
/// Summary description for WebForm1.
public class WebForm1 : System.Web.UI.Page
protected System.Web.UI.WebControls.Image Image1;
private void Page_Load(object sender, System.EventArgs e)
Image1.ImageUrl = Server.MapPath("")+"temp.jpg";
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
private void InitializeComponent()
this.Load += new System.EventHandler(this.Page_Load);
private void DisplayLine()
Bitmap b =new Bitmap(250,250);
Graphics g = Graphics.FromImage(b);
Pen p = new Pen(Color.Blue);
That code SAVES the image. To SERVE the image, instead, you could use: