The bitmap file begins with a BITMAPFILEHEADER structure followed by a BITMAPINFOHEADER structure. The bit-count of the bitmap is stored in the biBitCount member of the BITMAPINFOHEADER structure.
See the following code.
___
[tt]
Private Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Function GetBitmapBitCount(FileName As String) As Integer
Dim FN As Integer, bfh As BITMAPFILEHEADER, bih As BITMAPINFOHEADER
FN = FreeFile
Open FileName For Binary Access Read As #FN
Get #FN, , bfh
Get #FN, , bih
Close #FN
GetBitmapBitCount = bih.biBitCount
End Function
Private Sub Form_Load()
MsgBox GetBitmapBitCount("C:\WINDOWS\Coffee Bean.bmp")
End Sub[/tt]
___
Since you are only interested in reading the bit-count, you can also rewrite this function in a more concise (but obscure) way, which does not require any type declarations.
___
[tt]
Private Function GetBitmapBitCount(FileName As String) As Integer
Dim FN As Integer
FN = FreeFile
Open FileName For Binary Access Read As #FN
Get #FN, 29, GetBitmapBitCount
Close #FN
End Function[/tt]