Reputation: 907
I am trying to create an HBITMAP from an array which will contain the color values for the Pixels. The thing is when I try to create a 24-bpp Bitmap, the CreateDIBItmap is using BGR values instead of RGB as I would like.
The code to create the Bitmap is as follows:
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)
This should create a Red background for all of the image, but instead it is blue.
Upvotes: 6
Views: 1457
Reputation: 1
If you load for instance *.bmp file to memory or rather you make a variable lets say DWORD cRef = 0xFF0000 and fill a memory with it, in second case you will see RED color, so the byte order is BGR in both cases (seen as 0xRRGGBB value in source code editor for mentioned variable). But! Try to call e.g. SetTextColor(hDc, cRef) or so. The very same value will be BLUE, so it will be a hell of an adaptation, because Windows convention for DIB bitmaps is just the opposite of Windows convention for e.g. HBRUSH objects. I'd really wonder in which way is this useful..
Upvotes: 0
Reputation: 612954
The Windows convention for DIB bitmaps is BGR. You can't change that. You will simply have to adapt to it.
Upvotes: 2