Fileinformations on BMP Files (Width, Height...)

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Fileinformations on BMP Files (Width, Height...)

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by tranquil.

Code: Select all

; Get BMP FileInformations (Width, Height and number of planes of an Image)
;
; by Tranquilizer/ Secretly!
; Email: mike_delling@web.de

; Procedure Returns 0 if everything went okay
;
; -1 > File could not be opened/ Found
; -2 > Not a BMP File?
;
; imageinfo\width   -> X Size
; imageinfo\height  -> Y Size
; imageinfo\planes  -> Number of Planes


Structure my_imageinfo
  width.l
  height.l
  planes.l
EndStructure

imageinfo.my_imageinfo

Procedure getbmpinfo(file$)
  Shared imageinfo
  If ReadFile(0, file$) <> 0
    header1.w = ReadByte(0): header2.w = ReadByte(0) ; Get File header
    If header1 = $42 And header2 = $4d
      FileSeek(0, 18)
      imageinfo\width = ReadLong(0)
      imageinfo\height = ReadLong(0)
      imageinfo\planes = ReadWord(0)  
    Else
      res = -2 ; Wrong Fileformat  
    EndIf
    CloseFile(0)
  Else
    res = -1 ; Could not open File
  EndIf
  ProcedureReturn res
EndProcedure


Tranquilizer/ Secretly!
Registred PureBasic User