AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
November 2004

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2004.11.14 19:05 "Libtiff in Delphi", by Lars-goran Edholm
2004.11.16 10:31 "Re: Libtiff in Delphi", by Joris Van Damme

2004.11.16 10:31 "Re: 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