Converting images to TIF are becoming inverted (white on black)

  • Nelson

    Nelson - 2013-07-04

    Hello, I have been using FreeImage for VB6 (with the wrapper for VB6) for some time now to convert various images (GIF, JPEG, BMP, etc.) to TIF images with CCITG4 compression at 1bpp. The resulting images need to be 1bpp (black and white) for the app they are going into. This process has been working and the resulting TIF looks ok - mostly a white background with black text or images.

    However, recently I moved my code to C# and am doing the same process, but the resulting TIF images have the black and white inverted. Basically I'm getting black background images with white letters and images. I noticed that the SaveEx function in the VB6 code might be doing some things a little differently regarding colordepth compared to the SaveEx in the C# library, but I'm not sure what to do. Here is my old simple VB6 example code (converting a comic strip I simply saved off Google as a GIF image file):

    Dim dib As Long
    Dim bOK As Long
    ' Load a gif image
    dib = FreeImage_Load(FIF_GIF, "C:\Temp\Pickles.gif", 0)
    ' Save this image as TIF
    bOK = FreeImage_SaveEx(dib, "C:\Temp\Out.tif", FIF_TIFF, FISO_TIFF_CCITTFAX4, FICD_1BPP)
    ' Unload the dib
    FreeImage_Unload (dib)

    The resulting image looks ok - white background with black text/images. Now here is the same code in C# code:

    using FreeImageAPI;

    //load image
    //save image
    // unload bitmap
    FreeImage.UnloadEx(ref dib);

    This works, but the black and white are reversed. How can I change/fix this? Any example code and help would be greatly appreciated! Thank you for your time.

    I'm currently using VS2010 on Win7 Ultimate x64. FreeImage DLL v3.15.4 and I used the build.bat file to create the FreeImageNET.dll which I referenced into my project.

    Best Regards,


  • Carsten Klein

    Carsten Klein - 2013-07-04

    Hi Nelson,

    try to OR the color depth constant FICD_01_BPP with the FICD_FORCE_GREYSCALE when calling SaveEx. So, call SaveEx with


    as the fifth argument.


  • Nelson

    Nelson - 2013-07-12

    ** UPDATE - Even though the image looks fine now when forcing to greyscale (and opened in the windows image viewer), when it gets imported into our imaging system, the black & white get inverted back. I inspected the TIF header for a TIF that works in our system and it shows that Photometric Interpretation is 0 is white. Any ideas how to switch the photometric value?

    Thank you Carsten! I just got around to trying this and it worked! However, the image background, that I was expecting to be solid white, was grainy (but not solid black anymore). I ended up changing the call from using FICD_01_BPP to FICD_01_BPP THRESHOLD as follows:


    and that worked (showing just black and white). I have a question regarding this FICD_01_BPP_THRESHOLD - I have seen a MINISBLACK or MINISWHITE property value somewhere before. Is this how the THRESHOLD is determined here? Just curious to know if I need or should set that somewhere first before making the SaveEx call.

    (The reason I'm having to use this 1bpp fax format is the application these images go into is very old and it's what it supports). :(

    Thank you again for your time and help! I really appreciate it.

    Kindest Regards,

    Last edit: Nelson 2013-07-12

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks