您的位置:首页 > 其它

创建WINCE下16位格式位图实现快速BitBlt

2011-04-19 14:29 393 查看
在WINCE下,如果创建的位图与屏幕设备格式不一样,将会导致BitBlt函数极为缓慢,因此需要创建一幅16位色565格式位图,用此方法创建出的位图可以提供1ms的快速BitBlt绘制。当然,如果设备不是565颜色格式的,更改代码中的颜色掩码位bmiColors就可以了。

//////////////////////////////////////////////////////////////////////////
/// @brief      创建一幅缓存图像。
/// @param[out]  pHBitmap 生成的位图句柄。
/// @param[out]  pData	生成的位图中的数据位置。
/// @param[in]  hDC 目标DC句柄。
/// @param[in]  width 位图宽度。
/// @param[in]  height 位图高度。
/// @param[in]  bitCount 每个像素占多少个bit。
/// @attention  创建的位图是无压缩格式的。
/// @author    Loongee
/// @date      2010/01/15
//////////////////////////////////////////////////////////////////////////
void CreateBufferBitmap(HBITMAP* pHBitmap, void** pData,
HDC hDC, LONG width, LONG height, WORD bitCount)
{
BITMAPINFO& bmpInfo = *(BITMAPINFO*)new BYTE[sizeof(bmpInfo) + sizeof(RGBQUAD) * 3];
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = width;
bmpInfo.bmiHeader.biHeight = height;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = bitCount;
if (bitCount == 16)
{
bmpInfo.bmiHeader.biCompression = BI_BITFIELDS;
*(DWORD *)(&bmpInfo.bmiColors[0]) = 0xF800;
*(DWORD *)(&bmpInfo.bmiColors[1]) = 0x07E0;
*(DWORD *)(&bmpInfo.bmiColors[2]) = 0x001F;
}
else
{
bmpInfo.bmiHeader.biCompression = BI_RGB;
}
bmpInfo.bmiHeader.biSizeImage = 0;
bmpInfo.bmiHeader.biXPelsPerMeter = 1000;
bmpInfo.bmiHeader.biYPelsPerMeter = 1000;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
*pHBitmap = CreateDIBSection(hDC, &bmpInfo, DIB_RGB_COLORS
, pData, NULL, 0);
delete[] (BYTE*)&bmpInfo;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: