Информация о BMP-файлах

Материал из DRKB


{
  This tip show, how to get the filesize, width, height, bitcount and color used
  from a bitmap.

  Dieses Beispiel zeigt, wie man Dateigrosse, breite, hohe, Farbtiefe und Farbanzahl
  von einem Bitmap ausliest.
}

procedure TForm1.Button1Click(Sender: TObject);
var
  FileHeader: TBitmapFileHeader;
  InfoHeader: TBitmapInfoHeader;
  s: TFileStream;
begin
  s := TFileStream.Create('c:\YourBitmap.bmp', fmOpenRead);
  try
    s.Read(FileHeader, SizeOf(FileHeader));
    s.Read(InfoHeader, SizeOf(InfoHeader));
  finally
    s.Free;
  end;
  ListBox1.Items.Clear;
  ListBox1.Items.Add('Filesize: ' + IntToStr(FileHeader.bfSize));
  ListBox1.Items.Add('Width:    ' + IntToStr(InfoHeader.biWidth));
  ListBox1.Items.Add('Height:   ' + IntToStr(InfoHeader.biHeight));
  ListBox1.Items.Add('BitCount: ' + IntToStr(InfoHeader.biBitCount));
  ListBox1.Items.Add('Used:     ' + IntToStr(InfoHeader.biClrUsed));
end;

{
  BitCount:
  1 = black/white
  4 = 16 colors
  8 = 256 colors
}


ID: 03781