Background
Most black and white TIFF images are saved such that 0 = White and 1 = Black. This equates to a Photometric value of 0 for MinIsWhite and 1 for MinIsBlack. Some image viewers ignore this tag. this is code code it takes to convert from one to another using DotImage.
InvertCommand invert = new InvertCommand();
AtalaImage invertImage = invert.Apply(image).Image;
invertImage.Palette.SetEntry(0, Color.Black);
invertImage.Palette.SetEntry(1, Color.White);
invertImage.Save("MinIsBlack.tif", new TiffEncoder(), null;
If you simply wish to alter the tiff PhotometricInterpretation tag, you can use the following code:
string inFile = @"C:\badFile.tif";
string outFile = @"C:\fixedFile.tif";
TiffFile file = new TiffFile();
using (FileStream fs = new FileStream(inFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
file.Read(fs); for (int i = 0; i < file.Images.Count; i++) {
TiffTag tag = file.Images[i].Tags.LookupTag(TiffTagID.PhotometricInterpretation);
TiffTag newTag;
string data = tag.Data.ToString();
if (data == "0")
{
// Current PhotometricInterpretation: MinIsWhite
// Setting to MinIsBlack
newTag = new TiffTag(TiffTagID.PhotometricInterpretation, 1, TiffTagDataType.Short);
// NOTE: you may want to comment this out if your goal is to keep it MinIsWhite
}
else
{
// Current PhotometricInterpretation: MinIsBlack
// Setting to MinIsWhite
newTag = new TiffTag(TiffTagID.PhotometricInterpretation, 0, TiffTagDataType.Short);
}
file.Images[i].Tags.Remove(tag);
file.Images[i].Tags.Add(newTag);
// NOTE: this KB example is just switching the photometric tag.
// if you want to actually ensure that the palate entries match,
// you may want to implement something more akin to
// https://www.atalasoft.com/kb2/KB/50349/INFO-Typical-cause-of-an-inverted-black-and-white-TIFF-image
// if your issue is that you want to ensure the palate really is MinIsWhite
}
file.Save(outFile);
}
Original Article
Q10154 - HOWTO: Convert a MinIsBlack TIFF into a MinIsWhite TIFF
Last Update
2026-11-06 - TD - (Fixed outdated links)