Saving an image to disk with C#/ASP.NET

I received several requests from readers asking me to post an example of saving an image to disk.  So here it is. The following ASP.NET code demonstrates how to save a Bitmap object to a disk location.

using System;

using System.Drawing;
using System.Drawing.Imaging;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        // Bitmap object
        Bitmap bmp = new Bitmap(100, 200);  // This is just a black rectangle

        // Save to disk
        string fileName = "C:\\image.jpg";

        bmp.Save(fileName, ImageFormat.Jpeg);

        bmp.Dispose();  // Always make sure the image object is being disposed.

2 Responses to “Saving an image to disk with C#/ASP.NET”

  1. Jonathan Says:

    Thank you thank you! You made my day with this beautiful little piece of info!

  2., c#,javascript Says:, c#,javascript…

    […]Saving an image to disk with C#/ASP.NET « Le Bash Blog[…]…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: