2013-02-25 137 views
1

我想创建一个填充物,填充使用点列表创建的多边形的内部,但能够移除它的孔洞。带孔洞的填充多边形

我的旧代码:

Private Sub DrawSomething(ByVal points as List(of Point), _ 
ByVal myBrush As System.Drawing.Brush, _ 
ByVal myGraphics As System.Drawing.Graphics) 
    myGraphics.FillPolygon(myBrush, points) 
End Sub 

它只是填充在列表中的点的轮廓创造了一个多边形。

我怎样才能填补多边形,但不包括在它的孔(这是我知道的都在里面,我已经测试):

Private Sub DrawSomething(ByVal points as List(of Point), _ 
ByVal holes as List(of List(of Point)), _ 
ByVal myBrush As System.Drawing.Brush, _ 
ByVal myGraphics As System.Drawing.Graphics) 

' fill the contour created by points, excluding the contours created by holes 
End Sub 

有什么我可以使用,已经被创造出来的?我能以某种方式绘制原始多边形并移除这些孔吗?最好的方法是什么?

有什么我试过 - 例如:我也做了以下内容:

Private Sub DrawSomething(ByVal points as List(of Point), _ 
ByVal holes as List(of List(of Point)), _ 
ByVal myBrush As System.Drawing.Brush, _ 
ByVal myGraphics As System.Drawing.Graphics) 

    Dim myGraphicsPath As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath(Drawing2D.FillMode.Winding) 
    myGraphicsPath.AddLines(points) 
    Dim myRegion As System.Drawing.Region = New System.Drawing.Region(myGraphicsPath) 
    Dim otherGraphicsPath As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath(Drawing2D.FillMode.Winding) 
    ForEach otherPoints as List(of Point) in holes 
    otherGraphicsPath.AddLines(otherPoints) 
    Next 
    myRegion.Exclude(otherGraphicsPath) 
    myGraphics.FillRegion(myBrush, myRegion) 

End Sub 

这是没有那么糟糕...它排除了内部的多边形,但它也借鉴之间的“空”一大片轮廓。所以,我猜这是行不通的。

谢谢。

编辑:添加图片:enter image description here

轮廓被给定为点的列表(“点”),孔作为列表的列表(“孔”)。右边的图片对我得到的线条有粗略的描述(即使孔和轮廓没有共同点) - 线条随着我移动图像而改变。

+0

不知道我明白问题所在。你不能只是再次绘制多边形没有洞? – LarsTech 2013-02-25 23:01:27

+0

这就是我想要的。绘制多边形,没有洞。多边形内有孔的事实是必不可少的信息。所以我不能把它们掩盖起来。理论上我有所有的信息 - 我只是不知道如何正确绘制它。 – Thalia 2013-02-25 23:10:28

回答

1

尝试使用StartFigure和CloseFigure您GraphicPath对象:

For Each otherPoints as List(of Point) in holes 
    otherGraphicsPath.StartFigure() 
    otherGraphicsPath.AddLines(otherPoints) 
    otherGraphicsPath.CloseFigure() 
Next 

没有,我认为所有的对象都相互连接。

+0

我试过了,没有任何效果。谢谢。 – Thalia 2013-02-25 23:35:19

+0

我也尝试为每个图创建单独的区域,并排除它们。具有相同的效果。 – Thalia 2013-02-25 23:38:20

+0

@Mihaela否则我无法嘲笑它。仔细检查你的孔集合中的值。 – LarsTech 2013-02-25 23:39:09