Click here to Skip to main content
Click here to Skip to main content

C# Wrapper to the FreeImage DLL for graphical image format conversion

, 30 Sep 2003
Rate this:
Please Sign up or sign in to vote.
This article provides a simplified C# wrapper to the FreeImage project for graphical file format conversion.


FreeImage is an extremely useful Open Source project for reading, manipulating and converting a large amount of graphical formats. However at present the library exists as Win32 Dynamic Link Library. As my latest fascination is C#, I decided to create a simple Interop wrapper for it.

Using the code

The code is very straightforward to use, which is a reflection on the FreeImage implementation itself. For my needs I wanted to be able to take a picture file in Portable Bitmap (PBM) format and convert it to a standard Bitmap (BMP). For this I needed 3 methods exposed via the FreeImage DLL, FreeImage_Load, FreeImage_Save and FreeImage_Unload, the signature for which are:

       const char *filename, int flags FI_DEFAULT(0));
   FIBITMAP *dib, const char *filename, int flags FI_DEFAULT(0)); 
DLL_API void DLL_CALLCONV FreeImage_Unload(FIBITMAP* dib);

Now the C# Interop signatures for these are:

    public class FreeImage
         public static extern int FreeImage_Load(FIF format, 
                        string filename, int flags);
         public static extern void FreeImage_Unload(int handle);
         public static extern bool FreeImage_Save(FIF format, 
            int handle, string filename, int flags);

As an example, to convert a graphical image from PBM to BMP, all you need to do is the following (note the enum FIF is not documented here, but can be found in the source code).

namespace Test
    class MainClass
        public static void Main(string[] args)
            int handle = FreeImageAPI.FreeImage.FreeImage_Load(


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


About the Author

David Boland
Web Developer
United States United States
No Biography provided

Comments and Discussions

QuestionConversion of JPG to TGA gives zero KB TGA file Pinmemberdineshlepakshi16-Dec-13 15:24 
QuestionHow can I convert to JPG 2000 PinmemberAmerSawan28-Dec-12 5:21 
GeneralStill no luck on Windows Mobile 6 PinmemberPaul Kamath29-Oct-10 7:13 
Generalfreeimage.dll must be in your windows\system32 folder PinmemberPaul Kamath29-Oct-10 3:47 
Generalc# compact frmework Pinmembervertex_x3-Jun-08 11:22 
GeneralRe: c# compact frmework PinmemberRiyas Aboobaker24-Mar-09 7:28 
GeneralRe: c# compact frmework PinmemberRiyas Aboobaker24-Mar-09 19:39 
QuestionHelp, I am getting zero file size as result PinmemberRomashka_NN9-Apr-07 8:54 
AnswerRe: Help, I am getting zero file size as result PinmemberNoEscom15-Nov-07 22:37 
GeneralResquest.OutputStream Pinmemberkernellius4-Apr-07 13:03 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 1 Oct 2003
Article Copyright 2003 by David Boland
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid