Files Delphi

Title: Get the image size of a TIF image file
Question: How to get the image size of a TIF image File
Answer:
unit TifSize;
interface
Uses
Windows,Classes,SysUtils;
Procedure GetTifSize ( sFileName:String; Var iWidth,iHeight:Integer);
implementation
Type
TTifHeader = Record
Signature : WORD;
Version : Word;
IFD : DWORD;
End;
TIDF_Field = Record
Tag : Word;
FieldType : Word;
ValCount : DWord;
ValOffset : DWORD;
End;
Procedure GetTifSize ( sFileName:String; Var iWidth,iHeight:Integer);
VAR
TifFile : TFileStream;
Header : tTifHeader;
DirEntries : Word;
Field : TIDF_Field;
Cnt : Integer;
Begin
iWidth := -1;
iHeight := -1;
TifFile := TFileStream.Create ( sFileName, fmOpenRead );
Try
TifFile.Read ( Header,8);
TifFile.Position := Header.IFD;
TifFile.Read ( DirEntries, 2 );
For Cnt := 1 To DirEntries Do
Begin
TifFile.Read ( Field,12 );
Case Field.Tag OF
$0100 : iWidth := Field.ValOffset;
$0101 : iHeight := Field.ValOffset;
End;
IF ( iWidth-1) and ( iHeight-1)
Then Break;
End;
Finally
FreeAndNil ( TifFile );
End;
End;
end.