- 論壇徽章:
- 0
|
本帖最后由 youyou0 于 2011-12-20 17:18 編輯
今天項(xiàng)目中有一個(gè)問題,用DC在一個(gè)24位的bitmap上寫字體,字體竟然模糊了,因?yàn)閃indows Mobile的屏幕顏色深度是16位的。
以下是一位網(wǎng)友的代碼:
當(dāng)壓縮格式為 BI_BITFIELDS 時(shí),在位圖信息(即BITMAPINFOHEADER)后面接著三個(gè)DWORD型數(shù)據(jù),就是掩碼數(shù)據(jù),
一般為:0xF800(蘭色掩碼),0x07E0(綠色掩碼),0x001F(紅色掩碼),這是565的格式
如果為:0x7C00, 0x03E0, 0x001F, 則是555的格式(這也是bitcount=16,而壓縮標(biāo)志為BI_DIB時(shí)的默認(rèn)格式)
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 );
把這個(gè)位圖選入DC,然后draw text,字體就清楚了。
原因還不是很明白,應(yīng)該是從24位轉(zhuǎn)到16位,應(yīng)該不會(huì)出這個(gè)問題的啊,不能看到Microsoft的代碼。呵呵
特此記錄解決問題的辦法。
轉(zhuǎn)載自:http://www.cnblogs.com/goodcandle/archive/2008/06/24/1228743.html |
|