Compartilhar via


Curvas abertas e fechadas no GDI +

A ilustração a seguir mostra duas curvas: um em em aberto e outro fechado.

Interface gerenciada para curvas

Curvas fechadas têm um interior e, portanto, podem ser preenchidas com um pincel.The Graphics classe na GDI+ fornece os seguintes métodos para preencher formas fechadas e as curvas: FillRectangle, FillEllipse, FillPie, FillPolygon, FillClosedCurve, FillPath, e FillRegion. Sempre que você chamar um desses métodos, você deve passar um dos tipos específicos de pincel (SolidBrush, HatchBrush, TextureBrush, LinearGradientBrush, ou PathGradientBrush) sistema autônomo um argumento.

The FillPie método é um complemento para o DrawArc método. Assim sistema autônomo a DrawArc método desenha uma parte do estrutura de tópicos de uma elipse a FillPie 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 pizza preenchida.

The FillClosedCurve método é um complemento para o DrawClosedCurve método. Os dois métodos fechar automaticamente a curva conectando-se o ponto final ao ponto de partida.O exemplo a seguir desenha uma curva que passa através de (0, 0), (60, 20) e (40, 50).Em seguida, a curva é fechada automaticamente conectando-se (40, 50) para o ponto de partida (0, 0) e interior é preenchido com uma cor sólida.

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

The FillPath método preenche interiores as partes separadas de um caminho. Se uma parte de um caminho não formulário uma forma, a ou curva fechadaFillPath método fecha automaticamente esta parte do caminho antes de preenchê-lo. O exemplo a seguir desenha e preenche um caminho que consiste em um arco, um spline cardinais, uma seqüência de caracteres e uma pizza:

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

A ilustração a seguir mostra o caminho com e sem preenchimento sólido.Observe que o texto na seqüência de caracteres é contornado, mas não preenchido, a DrawPath método. É o FillPath método pinta interiores dos caracteres na seqüência de caracteres.

Consulte também

Tarefas

Como: Criar objetos gráficos para desenho

Referência

System.Drawing.Drawing2D.GraphicsPath

System.Drawing.Pen

System.Drawing.Point

Outros recursos

Linhas, curvas e formas

Caminhos Construindo e desenho