Displaying an Image in an aspx page as OutputStream using C#

Dear Viewers,

Here am going to give a solution to display an image in an aspx page as OutputStream by using c#.

First of all we need to remove all code in that aspx except the line of page tag (i.e., <%@ Page Language="C#")

In Page_Load

Do the code behind as follows,

Response.ContentType = "image/jpeg";
System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\test.jpg");
img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Yes, this the way to save image in aspx page as OutputStream.


No comments: