Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C#
Article

A C# Image Converter

Rate me:
Please Sign up or sign in to vote.
3.29/5 (19 votes)
3 Jan 2003Ms-PL1 min read 239.3K   3.6K   58   23
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, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralI tried to convert a EMF format file to a Bitmap file. the background turns to black Pin
hawkgao012925-Jul-10 20:35
hawkgao012925-Jul-10 20:35 
GeneralMy vote of 1 Pin
Guy Baseke21-Sep-09 4:24
Guy Baseke21-Sep-09 4:24 
QuestionUsing Win32 calls for Image conversion. Pin
kaviteshsingh1-Apr-08 20:57
kaviteshsingh1-Apr-08 20:57 
QuestionOverwrting the file casues JIT Error Pin
waliaps14-Dec-06 5:11
waliaps14-Dec-06 5:11 
QuestionQuery Pin
makarandg22-Feb-06 19:58
makarandg22-Feb-06 19:58 
Generalgif patent expired Pin
ralothh27-Aug-04 10:38
ralothh27-Aug-04 10:38 
GeneralOther formats Pin
8-Mar-02 2:16
suss8-Mar-02 2:16 
GeneralRe: Other formats Pin
Christian Graus4-Jan-03 1:02
protectorChristian Graus4-Jan-03 1:02 
GeneralWhich version of Framework Pin
17-Oct-01 7:23
suss17-Oct-01 7:23 
General[Message Deleted] Pin
Anonymous30-Aug-02 9:36
Anonymous30-Aug-02 9:36 
GeneralRe: Which version of Framework Pin
George Anescu28-Dec-02 11:09
George Anescu28-Dec-02 11:09 
GeneralGIF Pin
Chris Losinger26-Sep-01 4:46
professionalChris Losinger26-Sep-01 4:46 
GeneralRe: GIF Pin
George Anescu26-Sep-01 5:41
George Anescu26-Sep-01 5:41 
I have never used and I don't intend to use. This article is just showing some .NET capabilities. If somebody is using the code is his responsability to check in advance the legality of his actions.

GeneralRe: GIF Pin
5-Oct-01 11:23
suss5-Oct-01 11:23 
GeneralRe: GIF Pin
Chris Losinger5-Oct-01 12:32
professionalChris Losinger5-Oct-01 12:32 
GeneralRe: GIF Pin
11-Oct-01 6:11
suss11-Oct-01 6:11 
GeneralRe: GIF Pin
Christian Graus4-Jan-03 0:59
protectorChristian Graus4-Jan-03 0:59 
GeneralRe: GIF Pin
Mike Stevenson11-Oct-01 6:24
Mike Stevenson11-Oct-01 6:24 
GeneralRe: GIF Pin
Christian Graus4-Jan-03 1:00
protectorChristian Graus4-Jan-03 1:00 
GeneralRe: GIF Pin
fadi9-Jan-02 8:43
fadi9-Jan-02 8:43 
GeneralGIF: wrong. Pin
Chris Losinger9-Jan-02 8:50
professionalChris Losinger9-Jan-02 8:50 
GeneralRe: GIF Pin
rendle4-Apr-02 5:26
rendle4-Apr-02 5:26 
GeneralRe: GIF Pin
abstractsagacity20-Aug-04 23:07
abstractsagacity20-Aug-04 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.