简体   繁体   English

使用LibTiff.Net更新现有映像中的标记复制目录

[英]Updating Tags in an Existing Image with LibTiff.Net duplicates directory

I'm trying to change the values of a few custom ASCII tags in an existing TIFF image, as shown in the sample at http://bitmiracle.com/libtiff/help/add-custom-tiff-tags-to-an-existing-tiff-image.aspx . 我正在尝试更改现有TIFF图像中几个自定义ASCII标记的值,如http://bitmiracle.com/libtiff/help/add-custom-tiff-tags-to-an-中的示例所示existing-tiff-image.aspx

The changes essentially involve adding to the strings of existing tags, or adding custom tags that didn't exist. 这些更改主要涉及添加现有标记的字符串,或添加不存在的自定义标记。

However, when adding new tags, LibTiff seems to add a completely new directory at the end of the image, instead of changing the existing one, which is left in tact. 但是,在添加新标签时,LibTiff似乎在图像的末尾添加了一个全新的目录,而不是更改现有的目录。 I've verified this with WinHex and also tried a few different approaches such as WriteDirectory, CheckpointDirectory. 我已经使用WinHex验证了这一点,并尝试了一些不同的方法,如WriteDirectory,CheckpointDirectory。 The file is being opened for appending. 正在打开该文件以进行追加。

The duplicate directory causes a problem with another program out of our control which has to process the images. 重复目录导致我们无法控制的另一个程序出现问题,该程序必须处理图像。

Is there a way to just update the existing directory? 有没有办法只更新现有目录? Or, if it is necessary to rewrite the whole file, could I get some pointers please on how to do this? 或者,如果有必要重写整个文件,我可以得到一些指示,请问如何做到这一点? If the file is rewritten, there are other custom tags which will need to be preserved. 如果文件被重写,则还需要保留其他自定义标记。

If you add new tags to existing directory or changing some existing tags then you better replace existing directory with a new one. 如果将新标记添加到现有目录或更改某些现有标记,则最好使用新目录替换现有目录。 Otherwise you might get your tags overwrite raster data (because the updated directory needs more space than the older one). 否则,您可能会使标记覆盖栅格数据(因为更新的目录需要比旧版本更多的空间)。

So, you are right assuming that you need to rewrite the whole file if a program can't properly process files with updated directory chain. 因此,如果程序无法正确处理具有更新目录链的文件,则表示您需要重写整个文件。

You might want to look at source code of the TiffCP utility that comes with the library. 您可能希望查看库附带的TiffCP实用程序的源代码。 The source code should give you enough clues for a start. 源代码应该为您提供足够的线索以便开始。 The utility recompresses data in a file but you probably not required to do that. 该实用程序会重新压缩文件中的数据,但您可能不需要这样做。 You could just copy compressed data with ReadRawStrip and WriteRawStrip methods. 您可以使用ReadRawStripWriteRawStrip方法复制压缩数据。 The utility also copies all the tags. 该实用程序还会复制所有标记。 This is what you definitely need to do in your code (changing/adding tags at the same time). 这是您在代码中必须要做的事情(同时更改/添加标记)。

According to libbit.net documentation: Tiff.Open Method 根据libbit.net文档: Tiff.Open方法

only "r" "w" "a" mode is supported, plus some minor mode, there's no "r+" as in fopen to support both read and write to tiff. 只支持“r”“w”“a”模式,加上一些次要模式,没有“f +”,因为fopen支持读写tiff。

The native libtiff library has a utility which can be used to change specified tiff tag: 本机libtiff库有一个实用程序,可用于更改指定的tiff标记:

tiffset -s XResolution 400 test.tif tiffset -s XResolution 400 test.tif

tiffinfo test.tif can be used to verify the result. tiffinfo test.tif可用于验证结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM