问题描述
我有一个原始图像,其标签为 StripOffsets = 768.当我在内存中编辑图像然后将其写回文件时,我尝试手动将 StripOffsets 标签专门设置为与原始图像相同的值,即 768(使用以下方法).
//设置页面高度output.SetField(TiffTag.ROWSPERSTRIP, ttPage[i].Height);//设置页面偏移量output.SetField(TiffTag.STRIPOFFSETS, ttPage[i].StripOffset);
出于某种原因,最终结果是 StripOffsets = 8.为什么它不会按照我想要的方式设置 StripOffsets?附带说明,这也会影响
STRIPOFFSETS
标签由库在将图像数据写入文件时自动设置.
通常这个标签的值是什么并不重要(当然,除非它是正确的数字).
但有时会要求:图像数据必须保存在目录(页面)标题之后.某些应用程序要求以这种方式编写 TIFF.
在这种情况下,您应该在执行任何操作之前调用 CheckpointDirectory
方法将栅格数据写入文件或流以在栅格数据之前写入 TIFF 标记的方法.
CheckpointDirectory
将保存目录数据和标签数据,但不会关闭输出,您将能够继续创建图像.
您的代码应如下所示:
using (Tiff tif = Tiff.Open("file.tif", "w")){...tif.SetField(..);...tif.SetField(..);tif.CheckpointDirectory();...tif.WriteRawStrip(..);...}
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 themethods 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(..);
...
}
这篇关于使用 LibTiff.Net 2.3 库时,如何让 StripOffsets 标签保持不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!