reading a .bmp file in c++

女生的网名这么多〃 提交于 2019-12-03 03:09:13

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
jschroedl

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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!