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

通常,需要从一种图像文件格式转换为另一种图像文件格式。 可以通过调用 Image 类的 Save 方法并指定所需图像文件格式的 ImageFormat,轻松实现此转换。

以下示例从类型加载 BMP 图像,并将图像保存为 PNG 格式。

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

End Sub

编译代码

此示例需要:

  • Windows 窗体应用程序。

  • System.Drawing.Imaging 命名空间的引用。

另请参阅