|
发表于 2012-11-6 16:35:00
|
显示全部楼层
Re: 如何以最快的速度显示BMP图片?
如果是最精简的,那一定是win32的SetDIBitsToDevice()函数
这是核心代码:
- void DrawBmp(UINT* pBmp, int width, int height, int x, int y)
- {
- UINT* pSrc = pBmp;
- UINT* pDst = g_GDI.m_pBackBuffer + y*g_GDI.m_Width+x;
- for (int h=0; h<height; h++)
- {
- memcpy(pDst, pSrc, width*4);
- pSrc += width;
- pDst += g_GDI.m_Width;
- }
- }
- void MainLoop()
- {
- // 清空后台像素
- memset(g_GDI.m_pBackBuffer, -1, g_GDI.m_Width*g_GDI.m_Height*4);
- // 绘制
- DrawBmp(g_Bmp32, g_bmpWidth, g_bmpHeight, 10, 10);
- // 将g_GDI.m_pBackBuffer显示到屏幕
- ::SetDIBitsToDevice(g_GDI.m_hMainDC,
- 0, 0, g_GDI.m_Width, g_GDI.m_Height,
- 0, 0, 0, g_GDI.m_Height,
- g_GDI.m_pBackBuffer, &g_GDI.m_BmpInfo.m_BitmapInfo, DIB_RGB_COLORS);
- }
复制代码
足够简单吧?
ps:
附件包含了完整代码,其中图片就在代码中。 |
|