【发布时间】:2013-05-29 09:10:00
【问题描述】:
这是我的位图信息标头的文件结构
// the info header to store reveleant bitmap data
struct InfoHeader
{
unsigned int biSize; // the bit size
unsigned int width;
unsigned int height;
unsigned short biPlanes; // number planes
unsigned short biBitCount; // number of bits for each pixel
unsigned int biCompression; // compression used
unsigned int size; // size of image
unsigned int biXPelsPerMeter; // unit of measurement for x
unsigned int biYPelsPerMeter; // unit of measurement for y
unsigned int biClrUsed; // number of colours
unsigned int biClrImportant;
};
我相信它符合http://en.wikipedia.org/wiki/BMP_file_format上表示的结构
但是当我尝试通过
设置图像的大小时bitmapInfoHeader.size = (width*height*3);
宽度和高度都是无符号整数,大小总是设置为 0。 我已经玩了很久了,有什么帮助吗?
编辑:宽度和高度都通过参数传递给方法(writeBitmapFile)并且都被初始化(我已经测试过了)
谢谢。
【问题讨论】:
-
您使用 C 还是 C++ 作为编程语言?
-
请重新标记您的问题...哪种编程语言等...像这样的 awnser 是:
width或height为 0。 -
不应该是
bitmapInfoHeader.size = (bitmapInfoHeader.width*bitmapInfoHeader.height*3);吗?你有没有初始化过width和height?如果是这样,你能构造一个SSCCE 来重现问题吗? -
对不起,伙计们,它是 C++,宽度和高度都通过参数传递给方法(是的,宽度和高度都有值) 括号只是为了澄清之前要进行的计算将其分配给 .size 值。并且@Dukeling 无论如何,宽度和高度值都已分配给 infoheader.width 和 infoheader.height 值,它们完全相同,所以没关系:)
-
我修好了!结果发现 FileHeader 中的位对齐已关闭,需要使用 #pragma pack(2) 将 BitmapFileHeader 包含在内并使用 #pragma pack() 将其关闭,这确保了在读取二进制数据时结构中的短值正确对齐