以下是一位网友的代码:
当压缩格式为 BI_BITFIELDS 时,在位图信息(即BITMAPINFOHEADER)后面接着三个DWORD型数据,就是掩码数据,
一般为:0xF800(兰色掩码),0x07E0(绿色掩码),0x001F(红色掩码),这是565的格式
如果为:0x7C00, 0x03E0, 0x001F, 则是555的格式(这也是bitcount=16,而压缩标志为BI_DIB时的默认格式)
BITMAPINFO *bitmapInfo = (BITMAPINFO*)malloc( sizeof(BITMAPINFO)+sizeof(RGBQUAD)*(255) );
memset( bitmapInfo, 0, sizeof(BITMAPINFO)+sizeof(RGBQUAD)*(255) );
bitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfo->bmiHeader.biWidth = m_uWidth;
bitmapInfo->bmiHeader.biHeight = uLineCount*uLineHeight + m_uLineSpace*(uLineCount-1);
bitmapInfo->bmiHeader.biPlanes = 1;
bitmapInfo->bmiHeader.biBitCount = 16;
bitmapInfo->bmiHeader.biCompression = BI_BITFIELDS;
bitmapInfo->bmiHeader.biSizeImage = 0;
bitmapInfo->bmiColors[0].rgbBlue = 0;
bitmapInfo->bmiColors[0].rgbGreen = 0xF8;
bitmapInfo->bmiColors[0].rgbRed = 0;
bitmapInfo->bmiColors[0].rgbReserved = 0;
bitmapInfo->bmiColors[1].rgbBlue = 0xE0;
bitmapInfo->bmiColors[1].rgbGreen = 0x07;
bitmapInfo->bmiColors[1].rgbRed = 0;
bitmapInfo->bmiColors[1].rgbReserved = 0;
bitmapInfo->bmiColors[2].rgbBlue = 0x1F;
bitmapInfo->bmiColors[2].rgbGreen = 0;
bitmapInfo->bmiColors[2].rgbRed = 0;
bitmapInfo->bmiColors[2].rgbReserved = 0;
m_hBitmap = CreateDIBSection( m_hCompatibleDc, bitmapInfo, DIB_RGB_COLORS, &pBitmapBuffer, NULL, NULL );
GetObject( m_hBitmap, sizeof(DIBSECTION), &dibSection );
把这个位图选入DC,然后draw text,字体就清楚了。
原因还不是很明白,应该是从24位转到16位,应该不会出这个问题的啊,不能看到Microsoft的代码。呵呵
特此记录解决问题的办法。