我需要从 bmp 中获取宽度和高度值,以便稍后在位图中从原始像素数据创建 gdk 像素图时将它们作为参数传递。我对 BMP 格式做了一些研究,文件头应该是这样的:
struct Fileheader
{
    unsigned short Type;          // signature - 'BM'
    unsigned  long Size;          // file size in bytes
    unsigned short Reserved1;     // 0
    unsigned short Reserved2;     // 0
    unsigned long  OffBits;       // offset to bitmap
    unsigned long  StructSize;    // size of this struct (40)
    unsigned long  Width;         // bmap width in pixels
    unsigned long  Height;        // bmap height in pixels
    unsigned short Planes;        // num planes - always 1
    unsigned short BitCount;      // bits per pixel
    unsigned long  Compression;   // compression flag
    unsigned long  SizeImage;     // image size in bytes
    long           XPelsPerMeter; // horz resolution
    long           YPelsPerMeter; // vert resolution
    unsigned long  ClrUsed;       // 0 -> color table size
    unsigned long  ClrImportant;  // important color count
    Fileheader()
    {
        Size=Width=Height=Planes=BitCount=Compression=SizeImage=XPelsPerMeter= YPelsPerMeter=ClrUsed=ClrImportant=Type=StructSize=Reserved1=Reserved2=OffBits=0;}
    };
}
在以标准方式将 blob 提取到 row[0] 后
Fileheader fh;
memcpy(&fh, row[0], sizeof(Fileheader));
当
cout << "width: " << fh.Width << ", height: " << fh.Height << endl;
即:宽度:65536,高度:5626121834492592128
有人看到这里有什么问题吗?顺便说一句,我在一个 64 位的 linux 盒子上。