次の図は、開いている曲線と閉じた曲線の 2 つの曲線を示しています。
曲線の管理インターフェイス
閉じた曲線には内部があるため、ブラシで塗りつぶすことができます。 GDI+ の Graphics クラスは、閉じた図形と曲線を埋める次のメソッドを提供します。FillRectangle、FillEllipse、FillPie、FillPolygon、FillClosedCurve、FillPath、および FillRegion。 これらのメソッドのいずれかを呼び出すたびに、引数として特定のブラシの種類 (SolidBrush、HatchBrush、TextureBrush、LinearGradientBrush、または PathGradientBrush) のいずれかを渡す必要があります。
FillPie メソッドは、DrawArc メソッドのコンパニオンです。 DrawArc メソッドが楕円の輪郭の一部を描画するのと同様に、FillPie メソッドは楕円の内部の一部を塗りつぶします。 次の例では、円弧を描画し、楕円の内部の対応する部分を塗りつぶします。
myGraphics.FillPie(mySolidBrush, 0, 0, 140, 70, 0, 120);
myGraphics.DrawArc(myPen, 0, 0, 140, 70, 0, 120);
myGraphics.FillPie(mySolidBrush, 0, 0, 140, 70, 0, 120)
myGraphics.DrawArc(myPen, 0, 0, 140, 70, 0, 120)
次の図は、円弧と塗りつぶされたパイを示しています。
FillClosedCurve メソッドは、DrawClosedCurve メソッドのコンパニオンです。 どちらの方法でも、終点を始点に接続して曲線を自動的に閉じます。 次の例では、(0、0)、(60、20)、および (40, 50) を通過する曲線を描画します。 次に、曲線 (40, 50) を開始点 (0, 0) に接続することによって曲線が自動的に閉じられ、内部が純色で塗りつぶされます。
Point[] myPointArray =
{
new Point(0, 0),
new Point(60, 20),
new Point(40, 50)
};
myGraphics.DrawClosedCurve(myPen, myPointArray);
myGraphics.FillClosedCurve(mySolidBrush, myPointArray);
Dim myPointArray As Point() = _
{New Point(0, 0), New Point(60, 20), New Point(40, 50)}
myGraphics.DrawClosedCurve(myPen, myPointArray)
myGraphics.FillClosedCurve(mySolidBrush, myPointArray)
FillPath メソッドにより、パスの各部分の内側が塗りつぶされます。 パスの一部が閉じた曲線または図形を形成しない場合、FillPath メソッドはパスを塗りつぶす前にその部分を自動的に閉じます。 次の例では、円弧、カーディナル スプライン、文字列、円で構成されるパスを描画して塗りつぶします。
SolidBrush mySolidBrush = new SolidBrush(Color.Aqua);
GraphicsPath myGraphicsPath = new GraphicsPath();
Point[] myPointArray =
{
new Point(15, 20),
new Point(20, 40),
new Point(50, 30)
};
FontFamily myFontFamily = new FontFamily("Times New Roman");
PointF myPointF = new PointF(50, 20);
StringFormat myStringFormat = new StringFormat();
myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180);
myGraphicsPath.AddCurve(myPointArray);
myGraphicsPath.AddString("a string in a path", myFontFamily,
0, 24, myPointF, myStringFormat);
myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);
myGraphics.FillPath(mySolidBrush, myGraphicsPath);
myGraphics.DrawPath(myPen, myGraphicsPath);
Dim mySolidBrush As New SolidBrush(Color.Aqua)
Dim myGraphicsPath As New GraphicsPath()
Dim myPointArray As Point() = { _
New Point(15, 20), _
New Point(20, 40), _
New Point(50, 30)}
Dim myFontFamily As New FontFamily("Times New Roman")
Dim myPointF As New PointF(50, 20)
Dim myStringFormat As New StringFormat()
myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180)
myGraphicsPath.AddCurve(myPointArray)
myGraphicsPath.AddString("a string in a path", myFontFamily, _
0, 24, myPointF, myStringFormat)
myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110)
myGraphics.FillPath(mySolidBrush, myGraphicsPath)
myGraphics.DrawPath(myPen, myGraphicsPath)
次の図は、単色の塗りつぶしがある場合とない場合のパスを示しています。 文字列内のテキストは、DrawPath メソッドによってアウトライン化されますが、塗りつぶされません。 文字列内の文字の内部を塗りつぶす FillPath メソッドです。
パス
こちらも参照ください
- System.Drawing.Drawing2D.GraphicsPath
- System.Drawing.Pen
- System.Drawing.Point
- 線と曲線と図形
- 方法: 描画 用のグラフィックス オブジェクトを作成する
- パスの構築と描画
.NET Desktop feedback