【发布时间】:2020-06-21 14:23:13
【问题描述】:
我想复制一个 1 位 BMP 图像,我写了这段代码。我不知道为什么我的代码中 Header 结构的大小是 56,虽然它必须是 54。
我的 struct HeaderBMP 代码:
short _type; // file type
short _size;
int _reserved;
int _offset;
int _info_size;
int _width;
int _height;
short _planes;
short _bpp;
int _compression;
int _imagesize;
int _xresolution;
int _yresolution;
int _colours;
int _impcolours;
我无法达到 54 号,当我尝试修复时它只是 52 或 56 号。我希望你能帮我解决这个问题。
【问题讨论】:
-
不要在局部变量名上使用前导下划线。编译器在创建汇编代码时,会在所有名称上插入前导下划线,本地标签除外。
-
根据format of .bmp file,文件大小字段是 4 个字节,而不是 2 个字节。可能还有其他问题,但这应该可以帮助您朝着正确的方向开始。
-
根据底层硬件,
int可能是 2 或 4 或 8 个字节。最好使用来自stdint.h的类型或将每个字段定义为char的数组并根据需要执行隐式转换