
Thread
2004.11.16 10:31 "Re: [Tiff] Libtiff in Delphi", by Joris Van Damme
I'm trying to read Tiff tags in Delphi 7 but with no luck:
It's usefull to mention you are using LibTiffDelphi (http://www.awaresystems.be/imaging/tiff/delphi.html), because there are also LibTiff DLL's around that could be used in Delphi, and some issues probably are handled differently with those.
var
han:PTIFF;
begin
if OpenDialog1.Execute then
try
han:=TIFFOpen(OpenDialog1.FileName,'r');
showmessage(inttostr(TIFFGetField(han, TIFFTAG_IMAGEWIDTH)));
except
end;
TIFFClose(han);
end;
Two mistakes here:
- LibTiff does not raise exceptions. So get rid of the try...except...end scheme. Instead, you need to check the return of those functions to see if they worked or not.
- TIFFGetField takes a pointer as third argument, or pointers as third and fourth and so on. This is rather odd to you, as a Delphi programmer, Pascal does not support the varargs scheme. But it's a varargs C function you're calling. The tag value is returned in the memory pointed to by this third argument. The function return merely signals error status.
So your code should be (unchecked, from the top of my head):
var
han: PTIFF;
m: Cardinal;
begin
if OpenDialog1.Execute then
begin
han:=TIFFOpen(OpenDialog1.Filename,'r');
if han=nil then ... {respond to the error here}
if TIFFGetField(han, TIFFTAG_IMAGEWIDTH,@m)=0 then... {respond to the error here}
{m is now your image width}
end;
end;
Joris Van Damme
info@awaresystems.be
http://www.awaresystems.be
Download your free TIFF tag viewer for windows here:
http://www.awaresystems.be/imaging/tiff/astifftagviewer.html