Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


How to invoke the FreeImageBitmap constructor on a stream from unmanaged ("native") C++?

  • Hi all,

    I am developing an unmanaged ("native") C++ application in Visual Studio 2012, and I would like to be able to invoke the FreeImageBitmap constructor on a memory stream. As far as I can tell from

    the FreeImageBitmap constructor assumes managed code (.NET framework):
    Assembly: FreeImageNET (in FreeImageNET.dll)


    How to deploy the FreeImageBitmap constructor from unmanaged (“native”) C++ code?

    Best regards,

    Last edit: Baldur Steingrimsson 2014-02-02
  • Carsten Klein
    Carsten Klein

    Hi Baldur,

    first, I think that's not a FreeImage question but rather a MSVC/C++ question. Second, for to be honest, I have no idea whether (or how) it is possible to use managed code from an unmanaged C++ project. Actually, I'm quite sure that you cannot mix managed and unmanaged code that way.

    Microsoft actually extended C++ with .NET features to make it participate in .NET and managed code. I'm quite sure that this is the (only and recommended) way doing .NET in C++.

    There is a native C++ wrapper available, that ships with FreeImage. However, AFAIK, this wrapper is far from being complete and dos not necessarily rely on the latest version of FreeImage. Another option is using the C API of FreeImage from your C++ project.


  • Hervé Drolon
    Hervé Drolon


    To complete Carten answer, the C++ wrapper is always up-to-date with the native C API.
    Now if it is not complete, any suggestion is welcome :)


  • Carsten Klein
    Carsten Klein

    Hi Hervé,

    sorry for being not correct here. I was not aware, that the C++ wrapper is always up to date. However, I still think it does not provide all the functionality that is available through the C API, right?

    I guess, I've mixed that up with the PCRE library, in which I'm also involved a bit. The PCRE C++ wrapper is actually no longer under maintenance.


  • Hervé Drolon
    Hervé Drolon

    Hi Carsten,

    The C++ wrapper is fully compatible with the C library. You can pass a fipImage object to any C function instead of the expected FIBITMAP parameter, thanks to the operator FIBITMAP*().
    For example :

    fipImage src, dst;
    dst = FreeImage_ConvertTo8Bits(src);
    FreeImage_Save(FIF_TIFF, dst, "test.tif", 0);

    In case the C++ wrapper is not enough, then you can mix C code with C++ code.