Sunday, May 27, 2012

HOW TO READ BITMAP FILE INFORMATION

You can easily get information about bitmap files such the file size, image height & width, bit count and colors used.
The TBitmapFileHeader (tagBITMAPFILEHEADER - Windows API) record is declared in Windows.pas although it is not mentioned in Delphi help. The same situation is with the TBitmapInfoHeader
(tagBITMAPINFOHEADER - Windows API) record.

var
  BitmapFileHeader: TBitmapFileHeader;
  BitmapInfoHeader: TBitmapInfoHeader;
  FileStream      : TFileStream;
Begin
  // The file stream to the file. You should change the file path :-)
  FileStream := TFileStream.Create('C:\Documents and Settings\manel1\My Documents\My Pictures\slide.bmp',
    fmOpenRead);
  try
    FileStream.Read(BitmapFileHeader, SizeOf(BitmapFileHeader));
    FileStream.Read(BitmapInfoHeader, SizeOf(BitmapInfoHeader));
    memo1.Lines.Add('Type: ' + IntToStr(bitMapFileHeader.bfType));
    memo1.Lines.Add('Width: ' + IntToStr(BitmapInfoHeader.biWidth));
    memo1.Lines.Add('Height: ' + IntToStr(BitmapInfoHeader.biHeight));
    memo1.Lines.Add('Size: ' + IntToStr(BitmapInfoHeader.biSizeImage))
  finally
    FileStream.Free;
  end;
end;

0 comments:

Post a Comment

 
Related Posts Plugin for WordPress, Blogger...