I have an original image that has a tag StripOffsets = 768. When I edit the image in memory and then write it back to a file I try to specifically set the StripOffsets tag manually to the same value of the original which is 768 (using the following method).
//Set the height for the page
output.SetField(TiffTag.ROWSPERSTRIP, ttPage[i].Height);
//Set the offset for the page
output.SetField(TiffTag.STRIPOFFSETS, ttPage[i].StripOffset);
For some reason the end results is StripOffsets = 8. Why will it not set the StripOffsets the way I want? On a side note that also effects my "Page offset" shown in AWare Systems AsTiffTagViewer. I'm sure that has to do with the same issue. Somehow I'm not saving the tiff correctly. Maybe I can't manually set the "StripOffsets" tag and it is auto set? See my examples below...
STRIPOFFSETS
tag is set automatically by the library when it writes the image data to the file.
Usually it doesn't matter what is the value of this tag (unless it's correct number, of course).
But sometimes there is the requirement: image data must be saved after directory (page) header. Some applications require TIFFs to be written that way.
In such a case you should use a call to CheckpointDirectory
method before any of the
methods that write raster data to a file or a stream to write TIFF tags before raster data.
CheckpointDirectory
will save directory data along with tags data but won't close output and you'll be able to continue creating an image.
Your code should look something like this:
using (Tiff tif = Tiff.Open("file.tif", "w"))
{
...
tif.SetField(..);
...
tif.SetField(..);
tif.CheckpointDirectory();
...
tif.WriteRawStrip(..);
...
}
来源:https://stackoverflow.com/questions/9440004/how-can-i-get-the-stripoffsets-tag-to-stay-the-same-when-using-the-libtiff-net-2