共用方式為


HOW TO:繪製填滿材質的線條

更新:2007 年 11 月

除了繪製包含純色的線條之外,也可以繪製包含材質的線條。若要繪製包含材質的線條和曲線,請建立 TextureBrush 物件,然後將該 TextureBrush 物件傳遞至 Pen 建構函式。和材質筆刷關聯的點陣圖是用來拼接平面 (不可見),當畫筆繪製線條或曲線時,畫筆的筆觸會露出拼接材質的某些像素。

範例

下列範例會從 Texture1.jpg 檔案建立 Bitmap 物件。這個點陣圖是用來建構 TextureBrush 物件,而 TextureBrush 物件則是用來建構 Pen 物件。DrawImage 呼叫會繪製左上角位於 (0, 0) 的點陣圖。DrawEllipse 呼叫會使用 Pen 物件來繪製紋理橢圓形。

下圖顯示的是點陣圖和紋理橢圓形。

畫筆

Dim bitmap As New Bitmap("Texture1.jpg")
Dim tBrush As New TextureBrush(bitmap)
Dim texturedPen As New Pen(tBrush, 30)

e.Graphics.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height)
e.Graphics.DrawEllipse(texturedPen, 100, 20, 200, 100)

Bitmap bitmap = new Bitmap("Texture1.jpg");
TextureBrush tBrush = new TextureBrush(bitmap);
Pen texturedPen = new Pen(tBrush, 30);

e.Graphics.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height);
e.Graphics.DrawEllipse(texturedPen, 100, 20, 200, 100);

編譯程式碼

建立 Windows Form 並處理該表單的 Paint 事件。將上述程式碼貼至 Paint 事件處理常式中。請以系統中有效的影像取代 Texture.jpg。

請參閱

其他資源

使用畫筆繪製線條和形狀

Windows Form 中的圖形和繪圖