GDI+无闪烁绘图

GDI+无闪烁绘图

GDI+无闪烁绘图的原理就是不直接在OnDraw函数下绘图,而是先创建个Bitmap对象,然后用刚才的Bitmap对象创建一个Graphics的内存图像,然后所有的绘图操作都在
内存图像中进行,最后用DrawImage方法把内存图像显示到屏幕。
void CDataView::OnDraw(CDC* pDC)
{
    CDocument* pDoc = GetDocument();
    // TODO: 在此添加绘制代码
    pDC->TextOut(100,100,L"数据视图");

    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);

}

你可能感兴趣的:(GDI+无闪烁绘图)