GDI+使用双缓冲绘图

GDI+使用双缓冲绘图
————————————————————————
我再来详细解释一下刚才实现双缓冲的具体步骤:
1、在内存中建立一块“虚拟画布”:
Bitmap bmp = new Bitmap(600, 600);
2、获取这块内存画布的Graphics引用:
Graphics g = Graphics.FromImage(bmp);
3、在这块内存画布上绘图:
g.FillEllipse(brush, i * 10, j * 10, 10, 10);
4、将内存画布画到窗口中
this.CreateGraphics().DrawImage(bmp, 0, 0);
====================
maybe better
CDC dcMemory;
dcMemory.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc,1024,768);
dcMemory.SelectObject(&bmp);
 
Graphics _Graphics(dcMemory.m_hDC);
_Graphics.DrawImage(_pImage,0,0,1024,768);
//这是在GDI+中的写法。
 
dc.BitBlt(0,0,1024,768,&dcMemory,0,0,SRCCOPY);
 
_Graphics.ReleaseHDC(dcMemory.m_hDC);
dcMemory.DeleteDC();
bmp.DeleteObject();

注意:
OnEraseBkgnd(CDC* pDC)需要返回TRUE。
posted @ 2011-04-25 09:09  Watson.Long  阅读(9936)  评论(3编辑  收藏  举报