C
Mit CreateDIBSection.
bsp:
HBITMAP DIB24toDIB8(HBITMAP hBmp24, int cx, int cy)
{
BITMAPINFO bmInfo8;
memset(&bmInfo8,0,sizeof(BITMAPINFO));
bmInfo8.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmInfo8.bmiHeader.biWidth = cx;
bmInfo8.bmiHeader.biHeight = cy;
bmInfo8.bmiHeader.biPlanes = 1;
bmInfo8.bmiHeader.biBitCount = 8;
bmInfo8.bmiHeader.biCompression = BI_RGB;
// erzeuge eine 8 bit DIB
BYTE *pBits8=NULL;
HBITMAP hBitmap8 = CreateDIBSection(NULL,&bmInfo8,DIB_RGB_COLORS,(void**)&pBits8,NULL,0);
// selectiere die 8 bit DIB in einen DC
HDC hDC8 = CreateCompatibleDC(NULL);
HGDIOBJ hOldBmp8 = SelectObject(hDC8,hBitmap8);
// selectiere die 24 bit DIB in nen DC
HDC hDC24 = CreateCompatibleDC(hDC8);
HGDIOBJ hOldBmp24 = SelectObject(hDC24,hBitmap24);
// blite die DIB24 in die DIB8
// windows macht die frabraum konvertierung für dich
StretchBlt(hDC8,0,0,cx,cy,hDC24,0,0,cx,cy,SRCCOPY);
// Aufräumen
SelectObject(hDC24,hOldBmp24);
SelectObject(hDC8,hOldBmp8);
DeleteDC(hDC24);
DeleteDC(hDC8);
return hBitmap8;
}