winapi - 24bpp中的CreateDIBitmap是BGR而不是RGB

时间:2015-03-09 09:17:16

标签: c winapi rgb bitmapimage bgr

我正在尝试从一个数组创建一个HBITMAP,该数组将包含像素的颜色值。问题是当我尝试创建一个24-bpp的Bitmap时,CreateDIBItmap正在使用BGR值而不是我想要的RGB。

创建位图的代码如下:

 image_size = 600 * 600 * 3;
 aimp_buffer = (char *)malloc(image_size * sizeof(char));
 for (counter = 0; counter < image_size;)
 {
     aimp_buffer[counter++] = 255;
     aimp_buffer[counter++] = 0;
     aimp_buffer[counter++] = 0;
 }

 ads_scrbuf->avo_buffer = (void *)aimp_buffer;
 ads_scrbuf->im_height = 600;
 ads_scrbuf->im_width = 600;
 ads_scrbuf->im_scanline = 600;

 memset(&info, 0, sizeof(info));
 memset(&info.bmiHeader, 0, sizeof(info.bmiHeader));
 info.bmiHeader.biBitCount = 24;
 info.bmiHeader.biHeight= -600;
 info.bmiHeader.biWidth= 600;
 info.bmiHeader.biSize = sizeof(info.bmiHeader);
 info.bmiHeader.biPlanes = 1;
 info.bmiHeader.biCompression = BI_RGB;

 memset(&header, 0, sizeof(BITMAPV5HEADER));
 header.bV5Width = 600;
 header.bV5Height = 600;
 header.bV5BitCount = 24;
 header.bV5Size = sizeof(BITMAPV5HEADER);
 header.bV5Planes = 1;
 header.bV5Compression = BI_RGB;

 *adsp_hBitmap = CreateDIBitmap(GetDC(ds_apiwindow), (BITMAPINFOHEADER *)&header, 
     CBM_INIT, (void *)ads_scrbuf->avo_buffer, &info, DIB_RGB_COLORS)

这应该为所有图像创建一个红色背景,但它是蓝色。

1 个答案:

答案 0 :(得分:2)

DIB位图的Windows约定是BGR。你不能改变它。你只需要适应它。