How to: Convert a BMP image to a PNG image

Oftentimes, you will want to convert from one image file format to another. You can do this conversion easily by calling the Save method of the Image class and specifying the ImageFormat for the desired image file format.

Example

The following example loads a BMP image from a type, and saves the image in the PNG format.

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

Compiling the Code

This example requires:

  • A Windows Forms application.

  • A reference to the System.Drawing.Imaging namespace.

See also