松鼠的博客

导航

GDI+双缓冲技术

实现双缓冲的具体步骤

1、在内存中建立一块“虚拟画布”:

Bitmap bmp = new Bitmap(600600);


2、获取这块内存画布的Graphics引用:

Graphics g = Graphics.FromImage(bmp);


3、在这块内存画布上绘图:

g.FillEllipse(brush, i * 10, j * 101010);


4、将内存画布画到窗口中

this.CreateGraphics().DrawImage(bmp, 00);

 

(2)避免屏幕闪烁:GDI+双缓冲方案

Graphics g(pDC->m_hDC); 

CRect rcClient; 
GetClientRect(
&rcClient); 
Bitmap bmp(rcClient.Width(), rcClient.Height()); 
Graphics 
* buffergraphics = Graphics::FromImage(&bmp);//关键部分,创建一个内存图像
SolidBrush brush(Color(2550,0255)); 
buffergraphics 
->FillRectangle(&brush,00, rcClient.Width(),rcClient.Height()); //在内存图像中画图

g.DrawImage(
&bmp,00, rcClient.Width(), rcClient.Height());//将内存图像显示到屏幕
delete buffergraphics ; 
g.ReleaseHDC(pDC
->m_hDC);

posted on 2008-11-24 17:54  Xproer-松鼠  阅读(1099)  评论(0)    收藏  举报