Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A C# Image Converter

0.00/5 (No votes)
3 Jan 2003 1  
Presenting a smal C# Windows Application for converting images between different graphical formats

Sample Image - ImagConvert.jpg

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!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here