使用 LibTiff.Net 2.3 库时,如何让 StripOffsets 标签保持不变?

编程入门 行业动态 更新时间:2024-10-26 16:29:10
本文介绍了使用 LibTiff.Net 2.3 库时,如何让 StripOffsets 标签保持不变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个原始图像,其标签为 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 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(..);
 ...
}

这篇关于使用 LibTiff.Net 2.3 库时,如何让 StripOffsets 标签保持不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 10:36:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408791.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   Net   LibTiff   StripOffsets   库时

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!