想要实现的功能是画出多条直线后,可随机删除某一条。因为不是纯色背景,所以不能用背景色重绘。gdi+有异或画笔的功能吗?编程环境为win32 C++

解决方案 »

  1.   

    GDI+ 好像没有这种属性方法, 
    换种思路,可以把绘制好的背景存成内存位图,再需要时直接贴图
      

  2.   

    画直线前 保存 背景色 (GetPixel)?
      

  3.   

    Drawing a Line Filled with a Texture --------------------------------------------------------------------------------Instead of drawing a line or curve with a solid color, you can draw with a texture. To draw lines and curves with a texture, create a TextureBrush object, and pass the address of that TextureBrush object to a Pen constructor. The image associated with the texture brush is used to tile the plane (invisibly), and when the pen draws a line or curve, the stroke of the pen uncovers certain pixels of the tiled texture.The following example creates an Image object from the file Texture1.jpg. That image is used to construct a TextureBrush object, and the TextureBrush object is used to construct a Pen object. The call to Graphics::DrawImage draws the image with its upper-left corner at (0, 0). The call to Graphics::DrawEllipse uses the Pen object to draw a textured ellipse.Image         image(L"Texture1.jpg");
    TextureBrush  tBrush(&image);
    Pen           texturedPen(&tBrush, 30);graphics.DrawImage(&image, 0, 0, image.GetWidth(), image.GetHeight());
    graphics.DrawEllipse(&texturedPen, 100, 20, 200, 100);
    The following illustration shows the image and the textured ellipse. --------------------------------------------------------------------------------
      

  4.   

    双缓冲技术,把需要显示的部分先绘制到内存DC中。
    然后再OPaint中把内存DC复制到窗口DC中。以上是我目前在用的方法。
      

  5.   

    可以在绘制之前,可以将不需要绘制的区域(擦除的区域)排除掉,参考代码如下:
    void CEntityPen::Draw(HDC hDC, const Matrix *pMatrix)
    {
    ASSERT(pMatrix != NULL); ASSERT(hDC != NULL); Graphics graph(hDC);
    graph.SetSmoothingMode(SmoothingModeAntiAlias); graph.SetTransform(pMatrix); Pen pen(m_crDrawPen, m_nLineWidth);
    pen.SetLineCap(LineCapRound, LineCapRound, DashCapRound);
    pen.SetLineJoin(LineJoinRound); if(m_apEraseRegion[m_dwRegionIndex] != NULL)
    {
    graph.ExcludeClip(m_apEraseRegion[m_dwRegionIndex]);
    }
    graph.DrawPath(&pen, m_pDrawPath);
    }
      

  6.   


    void CMyImageDlg::TextBrush(CDC *pDC)
    {
    Image         image(L"水珠.jpg");
    TextureBrush  tBrush(&image);
    Pen           tPen(&tBrush, 10);
    Pen           rPen(Color(255,255,0,0),10);
    Graphics g(pDC->GetSafeHdc());
    g.DrawImage(&image,0, 0, image.GetWidth(), image.GetHeight());
    // 1 秒定时器 1改变 m_Erase
    if(m_Erase)
    {
    g.DrawLine(&tPen, 0, 0, image.GetWidth(), image.GetHeight());
    }
    else
    {
    g.DrawLine(&rPen, 0, 0, image.GetWidth(), image.GetHeight());
    }
    }