ASP.NET: Display an image from a stream

protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "image/jpg";
System.Drawing.Image image = System.Drawing.Image.FromFile("c:\temp\somefile.jpg");
image.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
}
This page loads an image from disk, converts it to a stream and writes it as the response for this page. The source would probably be binary data stored in a database or from a zip file in memory.

0 comments: