(C ++)奇怪的位图问题 - 灰度颜色

时间:2012-06-13 06:37:24

标签: c++ colors bitmap grayscale

我在C ++中创建一个Bitmap有一个奇怪的问题。我正在使用BITMAPFILEHEADER和BITMAPINFOHEADER结构来创建8位灰度图像。位图数据来自相机通过DMA,因为unsigned char与预期的长度完全相同。将图像保存为开头,它包含颜色?!

它应该是这样的:http://www.freeimagehosting.net/qd1ku
方式如下:http://www.freeimagehosting.net/83r1s

你有什么想法可以从中得到什么?

位图的标题是:

42 4D 36 00 04 00 00 00 00 00 36 00 00 00 28 00 00 00 00 02 00 00 00 02 00 00 01 00 08 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    Info-Header:
    42 4D           Its a Bitmap
    36 00 04 00     Size of Bitmap = 0x04 00 36 - Header-Size = 512x512
    00 00 00 00     Reserved
    36 00 00 00     Offset = Sizeof(Bitmapinfoheader);
    28 00 00 00     Sizeof(Bitmapinfoheader);
    00 02 00 00     =0x200 = 512 px.
    00 02 00 00     same
    01 00           = 1 - Standard. Not used anymore.
    08 00           Color dept = 8 bit.
    00 00 00 00     Compression: 0 = none.
    00 00 00 00     Filesize or zero
    00 00 00 00     X-Dot-Per-Meter, may be left 0
    00 00 00 00     y-Dot-Per-Meter, may be left 0
    00 00 00 00     If zero, all 255 colors are used
    00 00 00 00     If zero, no color table values are used

你有什么想法来自哪里?

1 个答案:

答案 0 :(得分:2)

在Windows下,如果您没有为8位图像提供调色板,则会为您提供系统默认调色板。我不记得win32添加调色板的方法,但它应该像创建256元素char数组一样简单,其中每个条目的值与其索引相同,并在适当的位置将其写入文件并更新偏移参数等