vico
vico

Reputation: 18251

Why Bitmap saves to PNG

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

Answers (2)

TheMri
TheMri

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

TheGeneral
TheGeneral

Reputation: 81593

From the documentation

Save(String)

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

Save(String, ImageFormat)

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

ImageFormat Class

Specifies the file format of the image.

Example

currentImmage.Save("image.bmp",ImageFormat.Bmp);

Upvotes: 5

Related Questions