How to: Convert Images from One Format to Another
This example demonstrates loading an image and saving it in several different graphics formats.
Example
class Program
{
static void Main(string[] args)
{
// Load the image.
System.Drawing.Image image1 = System.Drawing.Image.FromFile(@"C:\test.bmp");
// Save the image in JPEG format.
image1.Save(@"C:\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// Save the image in GIF format.
image1.Save(@"C:\test.gif", System.Drawing.Imaging.ImageFormat.Gif);
// Save the image in PNG format.
image1.Save(@"C:\test.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
Compiling the Code
You can compile the example at a command prompt or paste the code into a console application by using the IDE. In the latter case, you must reference the System.Drawing.dll file.
Replace "c:\test.bmp", "c:\test.jpg", "c:\test.gif" and c:\test.png with the actual file name.
See Also
Concepts
Designing a User Interface in Visual C#