X-Posting-Agent: Hamster/1.3.21.120 From: Peter Haas Newsgroups: borland.public.delphi.graphics Subject: Re: Extracting size info from Bitmap Date: Mon, 09 Apr 2001 19:16:05 +0200 References: <3ad1c9c0_2@dnews> X-Newsreader: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 62.157.76.154 Message-ID: <3ad1ed8b_2@dnews> X-Trace: dnews 986836363 62.157.76.154 (9 Apr 2001 10:12:43 -0700) Lines: 50 Path: dnews Xref: dnews borland.public.delphi.graphics:37139 Hi T., T. Busser wrote in <3ad1c9c0_2@dnews>: > I while back I read a post where someone explained how to get the dimensions > of a bitmap just by reading the header in the file instead of assigning it > to a TBitmap and accessing the properties width and height. The function return False, if the file is not a bitmap. function GetBitmapDimension(const AFilename: String; var AWidth, AHeight: Integer): Boolean; var f : TFileStream; bfh : TBitmapFileHeader; HeaderSize : DWord; w : Word; begin Result := False; AWidth := 0; AHeight := 0; f := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyNone); try f.ReadBuffer(bfh, SizeOf(bfh)); if bfh.bfType <> $4d42 then Exit; // 'BM' f.ReadBuffer(HeaderSize, SizeOf(HeaderSize)); case HeaderSize of SizeOf(TBitmapCoreHeader) : begin // OS/2 Bitmap f.ReadBuffer(w, SizeOf(w)); AWidth := w; f.ReadBuffer(w, SizeOf(w)); AHeight := w; end; SizeOf(TBitmapInfoHeader), SizeOf(TBitmapV4Header), SizeOf(TBitmapV5Header) : begin f.ReadBuffer(AWidth, SizeOf(AWidth)); f.ReadBuffer(AHeight, SizeOf(AHeight)); end; else Exit; // unknown Bitmap format end; // there are top down bitmaps with a negative height AHeight := Abs(AHeight); Result := True; finally f.Free; end; end; By Peter.