Saves this Image to the specified file or stream.
Namespace:
System.Drawing
Assembly:
System.Drawing (in System.Drawing.dll)
Visual Basic (Declaration)
Public Sub Save ( _
filename As String _
)
Dim instance As Image
Dim filename As String
instance.Save(filename)
public void Save(
string filename
)
public:
void Save(
String^ filename
)
public function Save(
filename : String
)
Parameters
- filename
- Type: System..::.String
A string that contains the name of the file to which to save this Image.
If no encoder exists for the file format of the image, the Portable Network Graphics (PNG) encoder is used. When you use the Save method to save a graphic image as a Windows Metafile Format (WMF) or Enhanced Metafile Format (EMF) file, the resulting file is saved as a Portable Network Graphics (PNG) file. This behavior occurs because the GDI+ component of the .NET Framework does not have an encoder that you can use to save files as .wmf or .emf files.
Saving the image to the same file it was constructed from is not allowed and throws an exception.
The following code example demonstrates how to call the Save method. This example is designed to be used with Windows Forms. Create a form that contains two buttons named Button1 and Button5. Paste the code into the form, and associate each method with the corresponding button's Click event.
Private Sub Button5_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button5.Click
Try
If (image1 IsNot Nothing) Then
image1.Save("c:\myBitmap.bmp")
Button5.Text = "Saved file."
End If
Catch ex As Exception
MessageBox.Show("There was a problem saving the file." _
& "Check the file permissions.")
End Try
End Sub
private void Button5_Click(System.Object sender, System.EventArgs e)
{
try
{
if (image1 != null)
{
image1.Save("c:\\myBitmap.bmp");
Button5.Text = "Saved file.";
}
}
catch(Exception)
{
MessageBox.Show("There was a problem saving the file." +
"Check the file permissions.");
}
}
private:
void Button5_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
try
{
if ( image1 != nullptr )
{
image1->Save( "c:\\myBitmap.bmp" );
Button5->Text = "Saved file.";
}
}
catch ( Exception^ )
{
MessageBox::Show( "There was a problem saving the file."
"Check the file permissions." );
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference