GDI+双缓冲技术
实现双缓冲的具体步骤
Bitmap bmp = new Bitmap(600, 600);
Graphics g = Graphics.FromImage(bmp);
g.FillEllipse(brush, i * 10, j * 10, 10, 10);
this.CreateGraphics().DrawImage(bmp, 0, 0);
Graphics g(pDC->m_hDC);

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

g.DrawImage(&bmp,0, 0, rcClient.Width(), rcClient.Height());//将内存图像显示到屏幕
delete buffergraphics ;
g.ReleaseHDC(pDC->m_hDC);
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);
(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(255, 0,0, 255));
buffergraphics ->FillRectangle(&brush,0, 0, rcClient.Width(),rcClient.Height()); //在内存图像中画图
g.DrawImage(&bmp,0, 0, rcClient.Width(), rcClient.Height());//将内存图像显示到屏幕
delete buffergraphics ;
g.ReleaseHDC(pDC->m_hDC);
浙公网安备 33010602011771号