whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

20 Visitors Online


 
...get the width and height of a Gif-File?
Autor: Rainer Kümmerle
Homepage: http://www.delphimania.de/
[ Print tip ]  

Tip Rating (3):  
     


type
  
TImageSize = record
    
Width: Integer;
    Height: Integer;
  end;

function ReadGIFSize(Stream: TStream): TImageSize;
type
  
TGifHeader = record
    
Signature: array [0..5] of Char;
    Width, Height: Word;
  end;
var
  
Header: TGifHeader;
begin
  
FillChar(Header, SizeOf(TGifHeader), #0);
  Result.Width := -1;
  Result.Height := -1;
  with Stream do
  begin
    
Seek(0, soFromBeginning);
    ReadBuffer(Header, SizeOf(TGifHeader));
  end;
  if (AnsiUpperCase(Header.Signature) = 'GIF89A') or
    
(AnsiUpperCase(Header.Signature) = 'GIF87A') then
  begin
    
Result.Width  := Header.Width;
    Result.Height := Header.Height;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  
FileName = 'D:\test.gif';
var
  
fs: TFileStream;
  gifsize: TImageSize;
begin
  
fs := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  try
    
gifsize := ReadGIFSize(fs);
    ShowMessage(Format('Breite %d Höhe %d', [gifsize.Width, gifsize.Height]));
  finally
    
fs.Free;
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners