Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Reading properties from a bitmap file (*.bmp)
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:
My application needs to display properties (width, height, color depth) of bitmaps in a selected directory. How can I obtain such properties?
Answer:
Bitmap files have two headers of type TBitmapinfoheader. Simply open the file and read them as shown in the example below.  | |  | | procedure TForm1.Button1Click(Sender: TObject);
var
FileHeader: TBitmapfileheader;
InfoHeader: TBitmapinfoheader;
sBmpFile : TFilestream;
begin
sBmpFile := TFilestream.Create('C:\Bild.bmp', fmOpenRead);
sBmpFile.Read(FileHeader, SizeOf(FileHeader));
sBmpFile.Read(InfoHeader, SizeOf(InfoHeader));
sBmpFile.Free;
with ListBox1.Items do
begin
Clear;
Add('File Size: ' + IntToStr(FileHeader.bfSize));
Add('Width: ' + IntToStr(InfoHeader.biWidth));
Add('Height: ' + IntToStr(InfoHeader.biHeight));
Add('Color Depth: ' + IntToStr(InfoHeader.biBitCount)); end;
end;
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|