I can't seem to find any documentation of how to delete a tiff tag using the LibTiff.Net library. I love the library but this one method is important to what I need to do. At one point I was hoping that I could just set a tag and set it's value to nothing. I had hoped that would work but that was a negative.
Anyone know how to delete a tiff tag using the LibTiff.Net library?
LibTiff.Net provides support for the Tag Image File Format (TIFF), a widely used format for storing image data.
While the TIFF specification permits an arbitrary set of tags to be defined and used in a file, the library only understands a limited set of tags. Any unknown tags that are encountered in a file are ignored.
Using LIBTIFF in your code. #include <tiffio.h> TIFF *tif=TIFFOpen ("input.tif", "r"); [Note: Though it works under Win32, you should not use the C-"malloc/free" and the C++-"new/delete" functions/operators to do the memory management for the reading buffer]
Note that unlike the stdio library TIFF image files may not be opened for both reading and writing; there is no support for altering the contents of a TIFF file. libtiffbuffers much information associated with writing a valid TIFF image.
Please have a look at TiffCP utility (and especially its source code) shipped with LibTiff.Net.
LibTiff.Net doesn't offer methods for removing tags (the same is true for LibTiff). You will need to implement part of TiffCP functionality in order to achieve that.
Basically, you will need to copy all tags you wish to retain, and copy pixels data without decoding and re-encoding it.
Please also have a look at Convert a multi-strip TIFF image to a single-strip one sample. It shows how to copy tags and copy raw (undecoded data) from one image to another. The sample actually decodes data in some cases because it needs to change number of strips, but you won't need to decode data.
I think you will have to basically copy the input file to a new TIFF image filtering out the tags you don't want in the process. Take a look at the tiffcp utility which is part of the regular libtiff distribution. It sort of does that, minus filtering.
Disclaimer: I've never used LibTiff.Net and am assuming that it is very similar to the LibTiff.
Take a look at tiffcp.c
First it manually copies/sets some known tags such as resolution, compression, colors etc. Then it copies all a set of tags that can be copied w/o preprocessing:
for (p = tags; p < &tags[NTAGS]; p++)
CopyTag(p->tag, p->count, p->type);
Then it copies the actual pixel data. This will from what I recollect, drop any tags that are not known to tiffcp. If your tag that you want to drop is in the list, you can trivially drop it by removing it from that list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With