如何:将 BMP 图像转换为 PNG 图像

更新:2007 年 11 月

有时,需要将一种图像文件格式转换为另一种格式。通过调用 Image 类的 Save 方法并指定对应于所需图像文件格式的 ImageFormat,可以很轻松地执行此转换。

示例

下面的示例从一个类型加载一个 BMP 图像,并以 PNG 格式保存该图像。

Private Sub SaveBmpAsPNG()
    Dim bmp1 As New Bitmap(GetType(Button), "Button.bmp")
    bmp1.Save("c:\button.png", ImageFormat.Png)

End Sub
private void SaveBmpAsPNG()
{
    Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp");
    bmp1.Save(@"c:\button.png", ImageFormat.Png);
}

编译代码

此示例需要:

  • Windows 窗体应用程序。

请参见

任务

如何:列出已安装的解码器

概念

位图类型

其他资源

在托管 GDI+ 中使用图像编码器和解码器