讀取 bmp 檔案的資訊

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

讀取 bmp 檔案的資訊

文章 tim »

讀取 .bmp 檔案的資訊.
其實在 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=
多多留言, 整理文章, 把經驗累積下來.....
回覆文章