4 out of 5 rated this helpful - Rate this topic

Image.Save Method (String, ImageFormat)

Saves this Image to the specified file in the specified format.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)
public void Save(
	string filename,
	ImageFormat format
)

Parameters

filename
Type: System.String
A string that contains the name of the file to which to save this Image.
format
Type: System.Drawing.Imaging.ImageFormat
The ImageFormat for this Image.
Exception Condition
ArgumentNullException

filename or format is null.

ExternalException

The image was saved with the wrong image format.

-or-

The image was saved to the same file it was created from.

The following code example demonstrates how to construct a bitmap from a type, and how to use the Save method. To run this example, paste the code into a Windows Form. Handle the form’s Paint event, and call the ConstructFromResourceSaveAsGif method, passing e as PaintEventArgs


private void ConstructFromResourceSaveAsGif(PaintEventArgs e)
{

    // Construct a bitmap from the button image resource.
    Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp");

    // Save the image as a GIF.
    bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);

    // Construct a new image from the GIF file.
    Bitmap bmp2 = new Bitmap("c:\\button.gif");

    // Draw the two images.
    e.Graphics.DrawImage(bmp1, new Point(10, 10));
    e.Graphics.DrawImage(bmp2, new Point(10, 40));

    // Dispose of the image files.
    bmp1.Dispose();
    bmp2.Dispose();
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Windows Embedded 7 (Trial) + 32bit Pixel Format
I have run into an issue upon the current trial edition of Windows 7 Embedded Standard, whereby in code I generate a "new Bitmap" with a pixel format of 32 bits ARGB, I process this image alter the alpha levels and then come to convert it into an Image, I then use that image, and finally as I have completed all the work I wish to cache the processed result (to save my having to repeat the same work next render cycle), upon calling Image.Save, with an image format of PNG, one receives an "ArgumentException" with information indicating that there is invalid Image Encoder information in Parameters 1 (i.e the image). $0$0 $0 $0If I convert the image to a second new Bitmap with a pixel format of 24bpp and then call save it is all fine, it appears under Windows 7 Embedded Standard, upon Framework v2.0 I cannot appear to save a user created 32bpp image in PNG format.$0 $0$0 $0 $0(Please note: I have not tried other save formats in 32bpp as yet and this is upon the Trial Release of Windows 7 Embedded Standard).$0