I\'m trying to load a bmp file for reusing it in opengl. I\'ve found some code via google on how to load a bmp file. I took this code and put in a class Bitmap in my project. Th
The header needs to be 2 byte aligned.
#pragma pack(2) // Add this
typedef struct
{
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;
#pragma pack() // and this
BITMAPINFOHEADER ::
You need to read first the biSize
in order to know how large the info header is, you cannot rely on sizeof()
.
Check out this wiki article about the file format
How about letting your Windows OS load it for you with LoadImage
.
HBITMAP hbm = LoadImage( NULL, path, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
Use GetObject()
to find further info like size, etc. and GetDIBits()
if you want to get at the individual bits.