GraphicsPath? 是類 ,但是相對於圖形還是路徑,它比較偏向路徑
GraphicsPath對象
它由壹系列相互連接的直線、曲線連接起來組成的開放(非閉合)圖形。
創建路徑時就會隱式創建壹個新圖形(由上面的直線、曲線等組成)。也可以
?顯示地聲明StartFigure。?
圖形具有方向,其先後順序加入的直線、曲線等就表明了次序。
壹般圖形路徑是開放的,由起點,到最後圖形(終點)。也可以用ClosedFigure顯式?聲明為閉合圖形(比如填充和剪輯時要用)
路徑
GraphicsPath 允許將各種形狀收集到壹個單獨的單元(如同集合壹樣)中。
它用AddLine,AddCurve、AddClosedCurve、AddPie等來添加形狀。
而且路徑還可添加到另壹個路徑中去,形成大型復雜路徑。
myGPath.AddPath(gp1,False)
最後繪制路徑:DrawPath(Pen,GP)
GraphicsPath方法
ClearMarkers ? 清除路徑的所有標記
SetMarkers 在GraphicsPath上設置標記
CloseFigure 閉合當前圖形,開始新圖
CloseAllFigure 閉合所有開放圖形,開始新圖
Flatten 將此路徑中的各段曲線轉換成相連的線段序列
GetBounds ?返回限定此GraphicsPath對象的矩形(外沿)
InitializeLifetimeService ?獲取控制此實例的生存期策略的生存期服務對象。
IsVisible ?指示指定點是否此GraphicsPath對象內
IsOutlineVisible ?指示當使用指定Pen對象繪制此GraphicsPath對象時,指定點
?是否包含在後者的輪廓內(下)
Reset ?清空PathPoints和PathTypes數組並將FillMode設置為Alernate
Reverse 反轉GraphicsPath對象PathPoints數組各點順序
Transform ?將變形矩形應用到此GraphicsPath對象
Warp ? 對此GraphicsPath對象應用由壹個矩形和壹個平等四邊形定義的扭曲變形
Widen ?在用指定的畫筆繪制此路徑時,用包含所填充區域的曲線代替此路徑
軌跡梯度刷
GraphicsPath按先後(軌跡)次序維護壹系列線條和曲線。
PathGradientBrush路徑漸變刷,在中心點可定義顏色,邊沿還可按軌跡分別指定顏色
C#使用GraphicsPath的AddString方法示例代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace advanced_drawing
{
public partial class Form14 : Form
{
public Form14()
{
InitializeComponent();
}
private void Form14_Paint(object sender, PaintEventArgs e)
{
// Create a GraphicsPath object.
GraphicsPath myPath = new GraphicsPath();
// Set up all the string parameters.string stringText = "Sample Text";
FontFamily family = new FontFamily("Arial");
int fontStyle = (int)FontStyle.Italic;
int emSize = 26;
Point origin = new Point(20, 20);
StringFormat format = StringFormat.GenericDefault;
// Add the string to the path.
myPath.AddString(stringText,
family,
fontStyle,
emSize,
origin,
format);
//Draw the path to the screen.
e.Graphics.FillPath(Brushes.Black, myPath);
}
}
}