Displaying Dynamically Generated Images in ASP.NET

June 8, 2009 | By

http://zabineziet.be/?topic=How-To-Earn-Money-Online-At-Home-In-Norway How To Earn Money Online At Home In Norway http://idealproteinrecipes.net/?options=Swiss-Forex-Trading-en-ligne-En-Ha%C3%AFti Swiss Forex Trading en ligne En Haïti http://dzineblog360.com/?opt=Binary-Option-Investment-Clubs-34652-Malaysia Binary Option Investment Clubs 34652 Malaysia http://zencio.com/?opt=National-Bank-Of-Macau-Macau-Stock-Exchange National Bank Of Macau Macau Stock Exchange http://cocomontaigne.com/?news=Real-Time-Forex-Rates-Mayotte Real Time Forex Rates Mayotte Real Time Forex Rates Mayotte http://zencio.com/?opt=National-Bank-Of-Macau-Macau-Stock-Exchange National Bank Of Macau Macau Stock Exchange As an example to demonstrate how to do this I created a project with two aspx pages. The first page, default.aspx, is the one the user views and it contains the Image control that will display the dynamically generated image. The second one contains the code to generate the image, named imagegen.aspx. Delete all the HTML code in imagegen.aspx and leave the Page directive only. So the contents of imagegen.aspx should look like this:

The code below is in imagegen.aspx’s Page Load event. It creates an image with a white background and writes the current date and time on it. The Bitmap object’s Save method allows you to save the image to a file or a stream. And saving the image to Response.OutputStream sends it to the outgoing HTTP body. To get the image displayed in default.aspx just set the ImageURL property of the Image control to “imagegen.aspx”. Now everytime default.aspx is loaded a new image is generated with the loading date and time displayed in it.


Listed at Hot Scripts in ASP.NET


Download Source Code




Filed in: ASP.NET | Tags: ,

Comments (5)

  1. Rukshan

    This was very helpful. Thank you very much for the article.

    Keep up the good work !!!

  2. Good one…But want to save the generated images in to a folder. How can we achieve that ?


  3. @Ramu, you could call image.Save() again and pass the file name as string.

  4. i search this code senks

  5. Dorababu

    Hi this works fine but on the web page I am getting some characters after running the code