C#中填写的一切,但GraphicsPath的 [英] c# fill everything but GraphicsPath

查看:766
本文介绍了C#中填写的一切,但GraphicsPath的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,看起来像:

  GraphicsPath的P =新的GraphicsPath(); 
//添加一定元素为p ...
// ...

g.FillPath(bgBrush,P);
//其中g:图形和bgBrush:刷



这导致东西,看起来像这样的:

 
### |
## |
## |

如何填充路径的准确补?



所需的输出

 
#|
## |
## |


解决方案

我很惊讶,没有人迄今回答 - 解决方案是非常简单的。只是一个矩形添加到路径和里面的一切得到恢复。

 保护覆盖无效的OnPaint(PaintEventArgs的E)
{
base.OnPaint(E);
图形G = e.Graphics;
g.Clear(背景色);

GraphicsPath的P =新的GraphicsPath(); $ B $B∥加上所需的路径
p.AddPie(100,100,100,100,0,270);
$ B $B∥加上矩形反转内侧
p.AddRectangle(新的Rectangle(50,50,200,200));

g.FillPath(Brushes.Black,P);
}


I have some code that looks like that:

GraphicsPath p = new GraphicsPath();
// Add some elements to p ...
// ...

g.FillPath(bgBrush, p);
// where g : Graphics and bgBrush : Brush

Which results in something that looks like this:

### |
  ##|
 ## |

How can I fill the exact complement of the path?

Desired output:

   #|
##  |
#  #|

解决方案

I'm surprised no one answered so far - the solution is pretty simple. Just add a Rectangle to the path and everything inside gets reverted.

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        Graphics g = e.Graphics;
        g.Clear(BackColor);

        GraphicsPath p = new GraphicsPath();
        // add the desired path
        p.AddPie(100, 100, 100, 100, 0, 270);

        // add the rectangle to invert the inside
        p.AddRectangle(new Rectangle(50, 50, 200, 200));

        g.FillPath(Brushes.Black, p);
    }

这篇关于C#中填写的一切,但GraphicsPath的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆