其實在 bmp 的檔案中, 前面的 BitmapFileHeader 及 BitmapInfoHeader 就有許多可讀的資訊, 可以讀出判定 bmp 圖檔的資訊!
範例程式碼如下:
代碼: 選擇全部
function ReadBMPINFO(filename: string):Boolean;
var
bfh: TBitmapFileHeader;
bih: TBitmapInfoHeader;
iFileHandle: Integer;
iBytesRead: Integer;
begin
Result := false;
iFileHandle := FileOpen(filename, fmOpenRead);
FileSeek(iFileHandle,0,0);
iBytesRead := FileRead(iFileHandle, bfh, sizeof(bfh));
if iBytesRead<>sizeof(bfh) then
exit;
iBytesRead := FileRead(iFileHandle, bih, sizeof(bih));
if iBytesRead<>sizeof(bih) then
exit;
FileClose(iFileHandle);
Result := true;
ShowMessage(format('Width * Height is %d * %d',[bih.biWidth, bih.biHeight]));
ShowMessage(format('Pixel Per Meter is %d * %d',[bih.biXPelsPerMeter, bih.biYPelsPerMeter]));
ShowMessage(format('Pixel Per Meter is %f * %f',[bih.biXPelsPerMeter / 100 *2.54, bih.biYPelsPerMeter / 100 *2.54]));
end;
另請參考 bmp 檔案格式: http://bbs.toseek.info/cgi-bin/topic.cg ... c=22&show=