Reputation: 18251
I have Bitmap object in my application. Why Save()
method saves to PNG
format file instead of BMP
?
Bitmap currentImmage;
...
currentImmage.Save("image.bmp");
Upvotes: 1
Views: 411
Reputation: 1297
From Microsoft Docs on Bitmap.Save(string)
Method:
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.
I believe you want to use Bitmap.Save(String, ImageFormat)
to save to a different format.
Upvotes: 3
Reputation: 81593
From the documentation
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.
Use instead
Saves this Image to the specified file in the specified format.
Specifies the file format of the image.
Example
currentImmage.Save("image.bmp",ImageFormat.Bmp);
Upvotes: 5