The format of bitmap files is described here on MSDN: it starts with a file header of 14 bytes, followed by a bitmap info header, which contains the information you're looking for in the field biBitCount
.
Edit:
As noted by iinspectable in the comments, the bitmap format can be complex. So with Windows, the best is to access to the information of the structures described above using the windows API.
If you're working cross platform, you'll have to take care yourself of many details:
the different file format versions: In fact you need to read the DWORD
(32 bits unsigned) at offset 14 of the file to find out which version of the data structure is used. The information you're looking fore is at offset 24 (core version) or 28 (other versions) of the file. It's a WORD
, so it's 16 bits unsigned.
the file format could be compressed. This is not the case for the core version. For the other versions, it's indicated in the following DWORD
(at offset 30).
all integers are stored in little endian.
But instead of doing all this by yourself, you could as well consider CImg or another library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…