Click here to Skip to main content
Licence Ms-PL
First Posted 25 Sep 2001
Views 174,064
Bookmarked 55 times

A C# Image Converter

By | 3 Jan 2003 | Article
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)

About the Author

George Anescu

Web Developer

Romania Romania

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralI tried to convert a EMF format file to a Bitmap file. the background turns to black Pinmemberhawkgao012920:35 25 Jul '10  
GeneralMy vote of 1 PinmemberGuy Baseke4:24 21 Sep '09  
QuestionUsing Win32 calls for Image conversion. Pinmemberkavitesh20:57 1 Apr '08  
Hi
I appreciate your effort for showing the image conversion capability on .Net. I would request if you have any Win32 code for these conversions which you can share.
 
I went to http://www.smalleranimals.com[^] site, one of the member has participated in the discussion. But it turns out they looking for money. And since i am building using all free tools including Visual studio express edition i would like not to overstep in costing.
 
Looking forward to positive response.
 
Regards
Kavitesh.
QuestionOverwrting the file casues JIT Error Pinmemberwaliaps5:11 14 Dec '06  
QuestionQuery Pinmembermak_gh19:58 22 Feb '06  
Generalgif patent expired Pinmemberraloth45610:38 27 Aug '04  
GeneralOther formats PinmemberAnonymous2:16 8 Mar '02  
GeneralRe: Other formats PinmemberChristian Graus1:02 4 Jan '03  
GeneralWhich version of Framework PinmemberAnonymous7:23 17 Oct '01  
General[Message Deleted] PinsussAnonymous9:36 30 Aug '02  
GeneralRe: Which version of Framework PinmemberGeorge Anescu11:09 28 Dec '02  
GeneralGIF PinmemberChris Losinger4:46 26 Sep '01  
GeneralRe: GIF PinmemberGeorge Anescu5:41 26 Sep '01  
GeneralRe: GIF PinmemberAnonymous11:23 5 Oct '01  
GeneralRe: GIF PinmemberChris Losinger12:32 5 Oct '01  
GeneralRe: GIF PinmemberAnonymous6:11 11 Oct '01  
GeneralRe: GIF PinmemberChristian Graus0:59 4 Jan '03  
GeneralRe: GIF PinmemberMike Stevenson6:24 11 Oct '01  
GeneralRe: GIF PinmemberChristian Graus1:00 4 Jan '03  
GeneralRe: GIF Pinmemberfadi8:43 9 Jan '02  
GeneralGIF: wrong. PinmemberChris Losinger8:50 9 Jan '02  
GeneralRe: GIF Pinmemberrendle5:26 4 Apr '02  
GeneralRe: GIF Pinmemberabstractsagacity23:07 20 Aug '04  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 4 Jan 2003
Article Copyright 2001 by George Anescu
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid