我用GDI+加载一张图片,后我做了一个放大镜在上面移动,鼠标移动到那个位置就放大它对应的区域。但是放大镜在移动时出现闪烁。有兴趣的朋友帮我解决一下。

解决方案 »

  1.   

    void CTestZoomDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default if(m_IsZoom)
    { mgraphics->DrawImage(myImage,drawrect,0,0,myImage->GetWidth(),myImage->GetHeight(),UnitPixel);         if((point.x>m_DisplayRect.left)&&(point.x<m_DisplayRect.right)&&(point.y>m_DisplayRect.top)&&(point.y<m_DisplayRect.bottom))
    {
    float h;
    float w;
          
    //比例尺
    w=float(myImage->GetWidth())/float(m_DisplayRect.Width());//对话框显现图片和实际图片,宽度比例尺
    h=float(myImage->GetHeight())/float(m_DisplayRect.Height());//高度比例尺
            
    //放大区域

    Rect rc;
    rc.X=point.x-60;   
    rc.Y=point.y-60-20;
    rc.Width=120;
    rc.Height=120;

            
    //被放大图片区域
            
    Rect rcd;
    rcd.X=point.x*w-60;  
    rcd.Y=(point.y-20)*h-60; 
    rcd.Width=100;  
    rcd.Height=100;
                   //图片放大
    if(m_IsZoom)
    {
    mgraphics->DrawImage(myImage,rc,rcd.X,rcd.Y,100,100,UnitPixel);
    }
    }
      
    }

    CDialog::OnMouseMove(nFlags, point);
    }
    刷新部分源码
      

  2.   

    mgraphics
    这个是什么
    --------------
    难道不能另建一个DC实现双缓冲?
    GDI+没用过
      

  3.   

    闪烁应该是没用双缓冲
    你把机制改一下
    把绘图操作集中在OnPaint中
    然后OnMouseMove只处理相关数据
    然后Invalidate
      

  4.   

    GDI+ 双缓存具体这么实现,能给出具体的代码吗?