我想创建一个填充多边形内部的“填充”,使用点列表创建,但能够删除它的孔。
我的旧代码:
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
这还不错......它确实排除了内部多边形,但它也在轮廓之间绘制了一片“空”。所以,我想这行不通。
谢谢你。
编辑:添加图片:
轮廓作为点列表(“points”)给出,孔作为列表列表(“holes”)给出。右边的图片有我得到的线条的粗略图(即使孔和轮廓没有共同点) - 当我移动图像时线条会发生变化。