Home : Image Processing : Image Clean-up/Correction Techniques : Convert a MinIsBlack TIFF into a MinIsWhite TIFF
Q10154 - HOWTO: Convert a MinIsBlack TIFF into a MinIsWhite TIFF

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)0;
// 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
// Q10069 - INFO: Typical cause of an inverted black and white TIFF image

// http://www.atalasoft.com/KB/article.aspx?id=10069
// if your issue is that you want to ensure the palate really is MinIsWhite
}
file.Save(outFile); }
Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved