I want to use the BITMAPINFO structure to define the DIB of the 32-bit png image, so that I can then use StretchDIBits to send the image to the printer for printing.
I tried the following code:
HDC memDC = CreateCompatibleDC(hdcPrinter);
BITMAPINFO bmi = { 0 };
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -static_cast<int>(height);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
void* bits = NULL;
HBITMAP dib = CreateDIBSection(memDC, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
//...
But I'm not sure if this will lose the alpha channel of the image.
Your
BITMAPINFOstructure is constructed correctly. As a sidenote, you can use Windows Imaging Component to convert.References: https://learn.microsoft.com/en-us/answers/questions/1360203/how-use-32bit-bitmap-for-menus-in-win32-app
https://github.com/microsoft/Windows-classic-samples/blob/ac06e54a15e9a62443e400fffff190fb978ea586/Samples/Win7Samples/winui/shell/appshellintegration/RecipeThumbnailProvider/RecipeThumbnailProvider.cpp#L249