Monday, September 18, 2006

How to display an image without creating a file? ( ASP.NET , C# )


PageWithImage.aspx.cs :
   public class PageWithImage : Page
{
private void Page_Load(object sender, EventArgs e)
{
using(Bitmap bmp = new Bitmap( blankW, blankH ))
using(Graphics g = Graphics.FromImage( bmp ))
{
g.FillRectangle( ... );
g.DrawString( ... );
g.DrawLine( ... );

Response.ContentType = "image/gif";
bmp.Save( Response.OutputStream, ImageFormat.Gif );
}

}
...
}

LandVP LLC

No comments: