简体   繁体   English

为什么将位图保存为PNG

[英]Why Bitmap saves to PNG

I have Bitmap object in my application. 我的应用程序中有Bitmap对象。 Why Save() method saves to PNG format file instead of BMP ? 为什么Save()方法保存为PNG格式的文件而不是BMP

Bitmap currentImmage;
...
currentImmage.Save("image.bmp");

From the documentation 从文档中

Save(String) 保存(字符串)

If no encoder exists for the file format of the image, the Portable Network Graphics (PNG) encoder is used . 如果图像的文件格式不存在编码器,则使用可移植网络图形(PNG)编码器 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. 当您使用Save方法将图形图像另存为Windows图元文件格式(WMF)或增强型图元文件格式(EMF)文件时,结果文件将另存为可移植网络图形(PNG)文件。 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. 出现此现象的原因是.NET Framework的GDI +组件没有可用于将文件另存为.wmf或.emf文件的编码器。

Use instead 改用

Save(String, ImageFormat) 保存(字符串,ImageFormat)

Saves this Image to the specified file in the specified format. 将该图像以指定格式保存到指定文件。

ImageFormat Class ImageFormat类

Specifies the file format of the image. 指定图像的文件格式。

Example

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

From Microsoft Docs on Bitmap.Save(string) Method : 从Microsoft Docs上的Bitmap.Save(string)方法

If no encoder exists for the file format of the image, the Portable Network Graphics (PNG) encoder is used. 如果没有用于图像文件格式的编码器,则使用可移植网络图形(PNG)编码器。 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. 当您使用Save方法将图形图像另存为Windows图元文件格式(WMF)或增强型图元文件格式(EMF)文件时,结果文件将另存为可移植网络图形(PNG)文件。 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. 出现此现象的原因是.NET Framework的GDI +组件没有可用于将文件另存为.wmf或.emf文件的编码器。

I believe you want to use Bitmap.Save(String, ImageFormat) to save to a different format. 我相信您想使用Bitmap.Save(String, ImageFormat)保存为其他格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM