次の方法で共有


GDI+ での開いた曲線と閉じた曲線

開いた曲線と閉じた曲線を次の図に示します。

開いた曲線と閉じた曲線

曲線の管理インターフェイス

閉じた曲線には内部があるため、ブラシを使用して塗りつぶすことができます。 GDI+ の Graphics クラスには、閉じた図形および曲線を塗りつぶすためのメソッドとして、FillRectangleFillEllipseFillPieFillPolygonFillClosedCurveFillPath、および FillRegion が用意されています。 これらのメソッドの 1 つを呼び出す場合は、特定のブラシ型 (SolidBrushHatchBrushTextureBrushLinearGradientBrush、または PathGradientBrush) の 1 つを引数として渡す必要があります。

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 メソッドのコンパニオン メソッドです。 この 2 つのメソッドは、終了点と開始点を連結することによって曲線を自動的に閉じます。 (0, 0)、(60, 20)、および (40, 50) を通過する曲線を描画する例を次に示します。 次に、(40, 50) と開始点 (0, 0) を連結することによって曲線を自動的に閉じ、内部を純色で塗りつぶします。

        Dim myPointArray As Point() = _
           {New Point(0, 0), New Point(60, 20), New Point(40, 50)}
        myGraphics.DrawClosedCurve(myPen, myPointArray)
        myGraphics.FillClosedCurve(mySolidBrush, myPointArray)

     Point[] myPointArray =
{ new Point(0, 0), new Point(60, 20), new Point(40, 50) };
     myGraphics.DrawClosedCurve(myPen, myPointArray);
     myGraphics.FillClosedCurve(mySolidBrush, myPointArray);

FillPath メソッドは、1 つのパスの各部分の内部を塗りつぶします。 パスの 1 つの部分が閉じた曲線または図形を形成していない場合、FillPath メソッドは、塗りつぶす前にパスのその部分を自動的に閉じます。 円弧、カーディナル スプライン、文字列、および扇形で構成されるパスを描画し、その内部を塗りつぶす例を次に示します。

        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)

     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);

純色で塗りつぶしたパスと、塗りつぶしていないパスを次の図に示します。 DrawPath メソッドによって文字列内のテキストのアウトラインは描画されていますが、内部は塗りつぶされていません。 文字列の文字の内部を塗りつぶすのは、FillPath メソッドです。

パスの文字列

参照

処理手順

方法 : 描画する Graphics オブジェクトを作成する

参照

System.Drawing.Drawing2D.GraphicsPath

System.Drawing.Pen

System.Drawing.Point

その他の技術情報

直線、曲線、および図形

パスの作成および描画