用函数CreateCompatibleDC创建内存DC,
CDC dcMem; //用于缓冲作图的内存DC
CBitmap bmp; //内存中承载临时图象的位图
dcMem.CreateCompatibleDC(pDC); //依附窗口DC创建兼容内存DC
bmp.CreateCompatibleBitmap(&dcMem,rect.Width(),rect.Height());//创建兼容位图
dcMem.SelectObject(&bmp); //将位图选择进内存DC
dcMem.FillSolidRect(rect,pDC->GetBkColor());
用CreateCompatibleBitmap()创建位图,使用bitblt显示到屏幕的是单色图像,不是彩色图像。
因为使用当调用CreateCompatibleDC创建一个兼容的DC时,新的DC将包含一个宽高为1,颜色为单色的默认位图,然后再调用CreateCompatibleBitmap时,创建的位图也是单色位图了。
解决办法:CreateCompatibleBitmap()要用实际设备DC
bmp.CreateCompatibleBitmap(&dcMem,rect.Width(),rect.Height());//创建兼容位图
改为
bmp.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());//创建兼容位图
最后显示的是彩色位图。