Shar1er80 Shar1er80 - 17 days ago 6
C# Question

BitMiracle.LibTiff.Net Converting oJPEG tiff to Bitmap results in a negative color image

I'm using the BitMiracle.LibTiff v2.4.560.0 to convert oJPEG tiffs to Bitmap. This has worked out great until just recently. A Tiff, that I tried converting, is a document with a white background and black text. After converting the tiff, the result ends up with a black background and white text.

I'm using this Convert from Tiff to Bitmap sample for my conversion.

Is this a bug with the BitMiracle.LibTiff library or does there need to be modifications to the sample code? I made quite a few attempts of modifying the sample code, but with no success.

Answer

It turns out the image that causes the issue has a TiffTag.PHOTOMETRIC of Photometric.MINISWHITE. Changing that property to Photometric.MINISBLACK resolves the issue.

Added this snippet to Convert from Tiff to Bitmap

FieldValue[] value = tif.GetField(TiffTag.PHOTOMETRIC);
if (value[0].ToInt() == (int)Photometric.MINISWHITE)
{
    tif.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
}
Comments