Convert the Format of an Image

Problem

You want to batch convert the format of one or more image files.

Solution

Use the Image.FromFile method to load the image, and use the Image.Save method overload that allows you to specify a new ImageFormat.

Discussion

.NET includes an impressive set of image-processing features. The core class is System.Drawing.Image, which allows you to open and save multiple types of images. The Image class supports the following formats:

  • Bitmap (BMP)

  • Enhanced Windows metafile image (EMF)

  • Exchangeable Image File (EXIF)

  • Graphics Interchange Format (GIF)

  • Windows icon (ICO)

  • Joint Photographic Experts Group (JPEG)

  • Memory bitmap (BMP)

  • W3C Portable Network Graphics (PNG)

  • Tag Image File Format (TIFF)

  • Windows metafile (WMF)

These formats are ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.