Beranda > Delphi > How to read bitmap file information

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.

tagBITMAPINFOHEADER Struct Reference – TBitmapInfoHeader
DWORD biSize Size of tagBITMAPINFOHEADER
LONG biWidth width of bitmap
LONG biHeight height of bitmap
WORD biPlanes 1
WORD biBitCount 1 (mono) or 4 (16 colors ) or 8 (256 colors) or 24 (16 Mil colors)
DWORD biCompression RLE COMPRESSION
DWORD biSizeImage Width x height
LONG biXPelsPerMeter
LONG biYPelsPerMeter
LONG biClrUsed Number of palettes used (if less than standard)
DWORD biClrImportant Number of important color
tagBITMAPFILEHEADER Struct Reference – TBitmapFileHeader
UINT bfType ‘B’ or ‘M’
DWORD bfSize Size of file
DWORD Reserved1 Reserved
UNIT Reserved2 Reserved
DWORD bfOffBits Byte location in the file which is first byte of image

var
  BitmapFileHeader: TBitmapFileHeader;
  BitmapInfoHeader: TBitmapInfoHeader;
  FileStream      : TFileStream;
Begin
  ...
  // The file stream to the file. You should change the file path :-)
  FileStream := TFileStream.Create('C:WindowsBubbles.bmp', fmOpenRead);
  try
    FileStream.Read(BitmapFileHeader, SizeOf(fileheader));
    FileStream.Read(BitmapInfoHeader, SizeOf(infoheader));
  finally
    FileStream.Free;
  end;
  ...
end;
Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: