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

GeneralRe: C:\projects\SVGTest\SVG.cs(145): Argument '2': cannot convert from 'int' to 'uint' PinmemberDavid Boland5-Aug-05 6:53 
Generaland now FreeImaged.dll :( Pinmemberleoni5101-Jul-05 8:23 
GeneralRe: and now FreeImaged.dll :( PinmemberDavid Boland1-Jul-05 8:35 
GeneralRe: and now FreeImaged.dll :( Pinmemberleoni5101-Jul-05 22:24 
GeneralRe: and now FreeImaged.dll :( Pinmemberalex_mp3-Dec-05 14:49 
GeneralI cant create FreeImage.dll Pinmemberleoni51026-Jun-05 9:19 
GeneralRe: I cant create FreeImage.dll Pinmemberianhfar30-Jun-05 7:01 
GeneralUnable to find an entry point (FreeImage_CloseMultiBitmap) Pinmemberjohn_b12321-Jun-05 1:58 
Why do I get the following error:
'Unable to find an entry point named FreeImage_CloseMultiBitmap in DLL FreeImage.dll.'
when trying to access CloseMultiBitmap function in FreeImage.dll.
I have used dumpbinGUI.exe to make sure it is there (see below)
Line From dumpbinGUI:
12 C 000294F0 _FreeImage_CloseMultiBitmap@8
Delcaration in .Net:
public static extern void FreeImage_CloseMultiBitmap(int imagefile);
I have successfully accessed FreeImage_Load,FreeImage_Unload,FreeImage_AppendPage
Mad | :mad:
GeneralRe: Unable to find an entry point (FreeImage_CloseMultiBitmap) PinmemberDeeJayX13-Mar-06 1:53 
GeneralRe: Unable to find an entry point (FreeImage_CloseMultiBitmap) PinmemberDeeJayX13-Mar-06 1:53 
AnswerRe: Unable to find an entry point (FreeImage_CloseMultiBitmap) Pinmembervor0nwe26-Apr-06 6:30 
GeneralDDS and Freeimage Pinmembercococvg27-Apr-05 1:23 
GeneralUnable to load DLL (FreeImage.dll). PinmemberTechTiger24-Mar-04 15:00 
GeneralRe: Unable to load DLL (FreeImage.dll). PinmemberDavid Boland25-Mar-04 0:55 
GeneralDisplaying in .NET Pinmemberfurkinfedup26-Oct-03 2:37 
GeneralRe: Displaying in .NET Pinmemberschoeneck10-Nov-03 12:22 
GeneralRe: Displaying in .NET PinmemberDavid Boland10-Nov-03 23:58 
GeneralRe: Displaying in .NET PinmemberDrolon17-Nov-03 8:15 
GeneralRe: Displaying in .NET Pinmemberfurkinfedup24-Jan-04 0:26 
GeneralRe: Displaying in .NET Pinmemberpersée23-Aug-05 5:41 
GeneralMemory or File... PinmemberDrew Stainton1-Oct-03 8:46 
GeneralRe: Memory or File... PinsussAnonymous1-Oct-03 23:38 
QuestionHow to draw FIBITMAP to form. PinmemberSkyer1-Oct-03 5:30 
AnswerRe: How to draw FIBITMAP to form. PinmemberDavid Boland1-Oct-03 6:09 
GeneralAccessing the image PinmemberRay Hayes1-Oct-03 2:36 

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
Web02 | 2.8.150224.1 | Last Updated 1 Oct 2003
Article Copyright 2003 by David Boland
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid