2004.10.19 19:22 "[Tiff] Changing TIFF value", by Richard Edwards
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);
// 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. The TIFFGetField call, however, returns 0 and the "result" variable remains empty.
Any thoughts? I greatly appreciate any help.
Thanks,
Richard