| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2004.10.21 18:10 "Re: Changing TIFF value", by Andrey KiselevOn Tue, Oct 19, 2004 at 12:22:50PM -0700, Edwards, Richard wrote:
> Hello. I'm having some trouble successfully changing TIFF values. I
> have scanned some of the archives. I'm adding the functionality in a
> Windows DLL.
>
> The primary problem seems to be that I cannot read my changed value
> successfully. Note that I am attempting to change the ARTIST field.
> I'm all but certain that the field does not exist in the original TIFF
> file.
>
> Here's my two functions:
>
> extern "C" __declspec (dllexport) BOOL WINAPI ReadTag(char *filename,
> long tag, char *result)
> {
> TIFF *image;
> long returncode, counter;
>
> // Open the TIFF file
> if((image = TIFFOpen(filename, "r")) == NULL)
> {
> return FALSE;
> }
>
> returncode = TIFFGetField(image, tag, result);
^^^^^^
The bug is here. Should be
returncode = TIFFGetField(image, tag, &result);
> // Close the file
> TIFFClose(image);
>
> return TRUE;
> }
>
> extern "C" __declspec (dllexport) BOOL WINAPI ChangeTag(char
> *filename, long tag, char *value)
> {
> TIFF *image;
> long returncode;
>
> // Open the TIFF file.
> if((image = TIFFOpen(filename, "a")) == NULL)
> {
> return FALSE;
> }
>
> returncode = TIFFSetField(image, tag, value);
>
> // Write data.
> returncode = TIFFRewriteDirectory(image);
>
> // Close the file
> TIFFClose(image);
>
> return TRUE;
> }
>
> Here's the body of the code:
>
> ReadTag("C:\\tmp\\sample.tif", 315, resultbuffer);
> ChangeTag("C:\\tmp\\sample.tif", 315, "RICHARD");
> ReadTag("C:\\tmp\\sample.tif", 315, resultbuffer);
>
> When I open the TIFF file after running the code in a binary editor, I
> see "RICHARD", which implies that ChangeTag had some success. As a
> matter of fact, I get an additional "RICHARD" every time I run the
> code, which isn't so great.
TIFFRewriteDirectory() adds the new directory at the end of the file
every time being called and we loose the space, occuped by the old
directories. So you should minimize the amount of TIFFRewriteDirectory()
calls.
Andrey
--
Andrey V. Kiselev
Home phone: +7 812 5274898 ICQ# 26871517
|
|||||||