Asked By Robert Simpson
24-May-07 06:58 PM

I've finally nailed down a problem with some TIFF's I've been generating in
.NET, and wanted to know where the blame may lay :)
I have some pretty simple code which saves a TIFF in Ccitt3 format.
However, when opening the resulting TIFF in something like Paint Shop Pro X
(as well as some other 3rd party viewers), the image is completely distorted
and horizontal bars appear all over the page.
I did some digging, and ran LIBTIFF's "tiffinfo" program against the TIFF's
coming out of my program. Invariably, tiffinfo complained "Bad value 0 for
Upon further research, I read in the TIFF spec:
-----
FillOrder
The logical order of bits within a byte.
Tag = 266 (10A.H)
Type = SHORT
N = 1
1 = pixels are arranged within a byte such that pixels with lower column
values are
stored in the higher-order bits of the byte.
2 = pixels are arranged within a byte such that pixels with lower column
values are
stored in the lower-order bits of the byte.
-----
As you can see, there is no "0" value documented.
I went into the binary file and manually altered the FillOrder field in the
TIFF to change it from 0 to 1, and viola -- PSP X and the other 3rd party
viewers were magically able to open and view my TIFF without any issues.
So ... my question(s) are:
I never set the fillorder, and I expect the TiffBitmapEncoder to do so ...
my saving method is nothing more than:
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Compression = TiffCompressOption.Ccitt3;
BitmapFrame frame = BitmapFrame.Create(target);
encoder.Frames.Add(frame);
using (FileStream fs2 = new FileStream("c:\\out.tif", FileMode.Create,
FileAccess.ReadWrite, FileShare.Read))
{
encoder.Save(fs2);
}
I even tried setting the fillorder progammatically with:
using (FileStream fs2 = new FileStream("c:\\out.tif", FileMode.Open,
FileAccess.ReadWrite, FileShare.Read))
{
decoder = new TiffBitmapDecoder(fs2,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
InPlaceBitmapMetadataWriter inmeta =
decoder.Frames[0].CreateInPlaceBitmapMetadataWriter();
if (inmeta.TrySave())
{
inmeta.SetQuery("/ifd/{short=266}", 1);
}
}
... but this didn't work. So what gives? For now I've resorted to opening
the file stream after saving, reading the TIFF header, and rewriting the
FillOrder tag myself.
Robert