Click here to Skip to main content
12,819,421 members (31,892 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 30 Sep 2003

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

You may also be interested in...

Comments and Discussions

AnswerRe: Unable to find an entry point (FreeImage_CloseMultiBitmap) Pin
vor0nwe26-Apr-06 6:30
membervor0nwe26-Apr-06 6:30 
GeneralDDS and Freeimage Pin
cococvg27-Apr-05 1:23
membercococvg27-Apr-05 1:23 
GeneralUnable to load DLL (FreeImage.dll). Pin
TechTiger24-Mar-04 15:00
memberTechTiger24-Mar-04 15:00 
GeneralRe: Unable to load DLL (FreeImage.dll). Pin
David Boland25-Mar-04 0:55
memberDavid Boland25-Mar-04 0:55 
The FreeImage dll does not expose any COM objects, only Win32 function pointers, and as such you cannot automatically generate the interrop assembly to communicate with it. This is the reason for this article, since I had to manually create the interrop interface myself. To use this wrapper and library all you need to do is make sure FreeImage.dll is available to your application on startup, the simpliest way to do this is place FreeImage.dll in the same directory as your application or to put it into one of the system directories. When you call the FreeImage.NET wrapper functions the runtime will automatically redirect the calls to their Win32 equilivants.;)

GeneralDisplaying in .NET Pin
furkinfedup26-Oct-03 2:37
memberfurkinfedup26-Oct-03 2:37 
GeneralRe: Displaying in .NET Pin
schoeneck10-Nov-03 12:22
memberschoeneck10-Nov-03 12:22 
GeneralRe: Displaying in .NET Pin
David Boland10-Nov-03 23:58
memberDavid Boland10-Nov-03 23:58 
GeneralRe: Displaying in .NET Pin
Drolon17-Nov-03 8:15
memberDrolon17-Nov-03 8:15 
GeneralRe: Displaying in .NET Pin
furkinfedup24-Jan-04 0:26
memberfurkinfedup24-Jan-04 0:26 
GeneralRe: Displaying in .NET Pin
persée23-Aug-05 5:41
memberpersée23-Aug-05 5:41 

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.

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