有点失望,没有人可以回答这个问题,但它确实发生了。所以我想出了一个解决方法,虽然并不理想,但希望能帮助陷入同样情况的其他人。也许有人会看到这一点并想出一个更优雅的解决方案。
所以一旦我有了最终的“阴影”多边形,我就找不到一个 VB.NET 解决方案来按原样绘制它,但这并不意味着我不能将它转换为可以在图片框中绘制的格式. 这是我想出的代码:
Private Sub createShadows()
Dim myPen As Pen
Dim myBrush As Brush
Dim myPoints As Point()
Dim listPoints As New List(Of Point)
Dim x As Double
Dim y As Double
' Convert the complex shape into a polygon shape in SQL and bring all the vertex
' points into VB and put into a string variable (curBlack)
mConn.Open()
Dim cmd = New SqlCommand("Select CurrentBlack.STCurveToLine().STAsText() From tbl_Map_Master Where MapID = " &
cmbDN.SelectedItem(0), mConn)
Dim curBlack As String = cmd.ExecuteScalar
mConn.Close()
' Now parse the vertex points from SQL format into a set of VB points
curBlack = curBlack.Replace("POLYGON ((", "").Replace(")", "") & ",,"
While curBlack.Length > 1
x = CInt(Strings.Left(curBlack, InStr(curBlack, " "))) * iZoom + centerX
curBlack = Strings.Right(curBlack, Len(curBlack) - InStr(curBlack, " "))
y = CInt(Strings.Left(curBlack, InStr(curBlack, ",") - 1)) * iZoom + centerY
curBlack = Strings.Right(curBlack, Len(curBlack) - InStr(curBlack, ",") - 1)
listPoints.Add(New Point(x, y))
End While
myPoints = listPoints.ToArray
' Now use the points array to draw a filled polygon
myPen = New Pen(Drawing.Color.White, 0)
myBrush = New SolidBrush(Color.FromArgb(170, 0, 0, 0))
Dim myGraphics As Graphics = pbDN.CreateGraphics
myGraphics.DrawPolygon(myPen, myPoints)
myGraphics.FillPolygon(myBrush, myPoints)
End Sub
正如我所说,这不是理想的解决方案,因此它会降低性能,但它确实有效。我肯定是一个 VB.NET 业余爱好者,哎呀,我什至无法让代码示例在此处正确显示,即使当前代码不是最佳的,但它可以完成工作。希望有人觉得这很有帮助。