Compartilhar via


Curvas abertas e fechadas no GDI+

A ilustração a seguir mostra duas curvas: uma aberta e outra fechada.

Screenshot of one open curve and one closed curve.

Interface gerenciada para curvas

Curvas fechadas têm um interior e, portanto, podem ser preenchidas com um pincel. A Graphics classe no GDI+ fornece os seguintes métodos para preencher formas e curvas fechadas: FillRectangle, , , , FillClosedCurve, FillPolygonFillPathFillEllipseFillPiee .FillRegion Sempre que você chamar um desses métodos, deverá passar um dos tipos de pincel específicos (SolidBrush, , , HatchBrushTextureBrushLinearGradientBrushou PathGradientBrush) como um argumento.

O FillPie método é um companheiro para o DrawArc método. Assim como o método desenha uma parte do contorno de uma elipse, o DrawArcFillPie método preenche uma parte do interior de uma elipse. O exemplo a seguir desenha um arco e preenche a parte correspondente do interior da elipse:

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)

A ilustração a seguir mostra o arco e a pizza preenchida.

Screenshot of an arc and the filled pie.

O FillClosedCurve método é um companheiro para o DrawClosedCurve método. Ambos os métodos fecham automaticamente a curva conectando o ponto final ao ponto inicial. O exemplo a seguir desenha uma curva que passa por (0, 0), (60, 20) e (40, 50). Em seguida, a curva é fechada automaticamente conectando (40, 50) ao ponto inicial (0, 0), e o interior é preenchido com uma cor sólida.

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)

O FillPath método preenche os interiores das partes separadas de um caminho. Se uma parte de um caminho não formar uma curva ou forma fechada, o FillPath método fechará automaticamente essa parte do caminho antes de preenchê-la. O exemplo a seguir desenha e preenche um demarcador que consiste em um arco, uma spline cardinal, uma cadeia de caracteres e uma pizza:

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)

A ilustração a seguir mostra o demarcador com e sem o preenchimento sólido. Observe que o texto na cadeia de caracteres é delineado, mas não preenchido, pelo DrawPath método. É o método que pinta o FillPath interior dos caracteres na corda.

String in a path

Confira também