Introduction
The conversion between different graphical image formats using the C#
programming language and the .NET Framework
is very easy in comparison with the Windows API
case where no direct support for such an operation is provided. You can open any image file format from the ones specified by a group of properties of ImageFormat
class:
Bmp
- Bitmap image format (extension .bmp
)
Emf
- Enhanced Windows metafile image format
Exif
- Exchangable Image Format
Gif
- Graphics Interchange Format image format (extension .gif
)
Icon
- Windows icon image format (extension .ico
)
Jpeg
- Joint Photographic Experts Group image format (extensions .jpg, .jpeg
)
MemoryBmp
- Specifies a memory bitmap image format
Png
- Specifies the W3C Portable Network Graphics image format (extension .png
)
Tiff
- Tag Image File Format (extension .tif
)
Wmf
- Windows metafile image format (extension .wmf
)
ImageFormat
class is in the System.Drawing.Imaging
namespace. The following code snippet is showing how it is done:
string strFileName = "FileName.jpg";
Bitmap bitmap = new Bitmap(strFileName);
Later you can save the bitmap in another graphical format specifying the new file name and graphical format like in the following code snippet:
strFileName = "FileName.gif";
bitmap.Save(oStrFileName, ImageFormat.Gif);
The source code of a fully operational Image Converter application is provided in the attached project ImagConvert.zip
. I am interested in any opinions and new ideas about this implementation.
Updates History
28 Dec 2002 - Update to VS.NET release with the code provided by M.H. Thanks!