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 Sub Save (
	filename As String,
	format As ImageFormat
)

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 Sub ConstructFromResourceSaveAsGif(ByVal e As PaintEventArgs)

    ' Construct a bitmap from the button image resource.
    Dim bmp1 As New Bitmap(GetType(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.
    Dim bmp2 As 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()
End Sub

.NET Framework
Available since 1.1
Return to top
Show: