在分析我的GDI +項目時,我發現以下IsLineVisible
函數是在我的自定義面板上繪製和移動對象時「最熱」的函數之一。優化GDI +功能的性能
有沒有可能優化它?
Private Function IsLineVisible(ByVal detectorRectangle As Rectangle,
ByVal pen As Pen,
ByVal ParamArray points() As Point) As Boolean
Using path As New GraphicsPath()
path.AddLines(points)
Return IsPathVisible(detectorRectangle, path, pen)
End Using
End Function
' Helper functions '''''''''''''''''''''''''''''''''''''
Private Function IsPathVisible(ByVal detectorRectangle As Rectangle,
ByVal path As GraphicsPath,
ByVal pen As Pen) As Boolean
If Not path.IsPoint Then
path.Widen(pen)
End If
Return IsPathVisible(detectorRectangle, path)
End Function
Private Function IsPathVisible(ByVal detectorRectangle As Rectangle,
ByVal path As GraphicsPath) As Boolean
Using r As New Region(path)
If r.IsVisible(detectorRectangle) Then
Return True
Else
Return False
End If
End Using
End Function
謝謝。但是你「忘記」了筆的寬度**(厚度)。 – serhio
是的,但我說的基本思想 - 你只需要計算兩條輪廓線,組成你的粗線並通過它們。如果其中一個是可見的 - 那麼你的粗線是可見的! –
這條線也可以有一個樣式:虛線,虛線... – serhio