我已經創建了一個簡單的測試應用程序,根據我提供的要點將多邊形繪製到圖像上。我已經創建了一個畫筆,它將填充多邊形,我想如何。現在我想填寫一切,但多邊形。所以,使用我的畫筆,我想繪製多邊形的周圍,所以可見的是多邊形內的東西。有誰知道我可以怎樣做到這一點?圖形FillPolygon外觀?
在此先感謝!
我已經創建了一個簡單的測試應用程序,根據我提供的要點將多邊形繪製到圖像上。我已經創建了一個畫筆,它將填充多邊形,我想如何。現在我想填寫一切,但多邊形。所以,使用我的畫筆,我想繪製多邊形的周圍,所以可見的是多邊形內的東西。有誰知道我可以怎樣做到這一點?圖形FillPolygon外觀?
在此先感謝!
我認爲System.Drawing.Graphics.Clip是你想要的。
下面是從鏈接代碼示例:
Private Sub SetAndFillClip(ByVal e As PaintEventArgs)
' Set the Clip property to a new region.
e.Graphics.Clip = New Region(New Rectangle(10, 10, 100, 200))
' Fill the region.
e.Graphics.FillRegion(Brushes.LightSalmon, e.Graphics.Clip)
' Demonstrate the clip region by drawing a string
' at the outer edge of the region.
e.Graphics.DrawString("Outside of Clip", _
New Font("Arial", 12.0F, FontStyle.Regular), _
Brushes.Black, 0.0F, 0.0F)
End Sub
向區域外補的一切,那麼你就必須確定DC的你繪製的程度,然後填補這個RECT,將Graphics.Clip設置爲從您的點創建的區域之後。
所以,你的代碼可能是這個樣子:
Private Sub SetAndFillClip(ByVal e As PaintEventArgs)
' Set the Clip property to a new region.
e.Graphics.Clip = GetRegionFromYourPoints()
' Fill the entire client area, clipping to the Clip region
e.Graphics.FillRectangle(Brushes.LightSalmon, GetWindowExtentsFromYourWindow())
End Sub
此鏈接顯示瞭如何從一個點的數組創建一個地區:
太棒了,我認爲這對我有用!感謝您的快速回復! – lhan 2011-02-01 13:38:58
我很驚訝沒有找到這個答案在任何地方,但在看文檔System.Drawing.Region 答案看起來很簡單。
我們可以從無限區域中排除多邊形(我假設需要是GraphicsPath)。 Region.XOR應該工作一樣在這種情況下,排除:
Region region = new Region();
region.MakeInfinite();
GraphicsPath polygonPath = GetYourPolygon();
region.Exclude(polygonPath);
e.Graphics.FillRegion(Brushes.Black, region);
在我來說,我只是需要排除一個普通的RectangleF,但是這並獲得成功,它填補了周圍地區,並獨自留在排除地區。
那些誰還沒有找到解決方案,看看this。爲我工作,開箱即用。
假設這是C#/ .NET?可能要在這裏編輯您的標籤。 – MusiGenesis 2011-01-31 18:47:15
對不起,我還不夠具體。它實際上是VB.net,儘管我認爲這些方法是相同的(功能性說法)。 – lhan 2011-01-31 20:42:02