다음을 통해 공유


GDI+의 그래픽 경로

경로는 선, 사각형 및 단순 곡선의 조합으로 이루어집니다. 벡터 그래픽 개요에서 다음과 같은 기본 빌딩 블록이 그림을 그리는 데 가장 유용하다는 사실을 설명했습니다.

  • 사각형

  • 타원

  • 원호

  • 다각형

  • 카디널 스플라인

  • 3차원 곡선 스플라인

GDI+에서는 GraphicsPath 개체를 사용하여 이러한 빌딩 블록 시퀀스를 하나의 단위로 모을 수 있습니다. 그런 다음 Graphics 클래스의 DrawPath 메서드를 한 번 호출하여 선, 사각형, 다각형 및 곡선의 전체 시퀀스를 그릴 수 있습니다. 다음 그림에서는 선, 원호, 3차원 곡선 스플라인 및 카디널 스플라인을 조합하여 만든 경로를 보여 줍니다.

경로

경로 사용

GraphicsPath 클래스는 그리려는 항목의 시퀀스를 만드는 데 사용할 수 있도록 AddLine, AddRectangle, AddEllipse, AddArc, AddPolygon, AddCurve(카디널 스플라인용) 및 AddBezier 메서드를 제공합니다. 이러한 메서드는 모두 오버로드됩니다. 즉 각 메서드는 다양한 매개 변수 목록을 지원합니다. 예를 들어 AddLine에서 변형된 한 메서드는 네 개의 정수를 받고 AddLine에서 변형된 다른 메서드는 두 개의 Point 개체를 받습니다.

AddLines, AddRectanglesAddBeziers 등과 같이 선, 사각형 및 3차원 곡선 스플라인을 경로에 추가하는 메서드는 한 번 호출하여 경로에 몇 개의 항목을 추가하는 동반 메서드를 여러 개 갖습니다. 또한 AddCurveAddArc 메서드는 폐곡선이나 원형을 경로에 추가하는 AddClosedCurveAddPie 메서드를 동반합니다.

경로를 그리려면 Graphics 개체, Pen 개체 및 GraphicsPath 개체가 필요합니다. Graphics 개체는 DrawPath 메서드를 제공하고 Pen 개체에는 경로를 렌더링하는 데 사용되는 선의 색과 두께 같은 특성이 저장됩니다. GraphicsPath 개체에는 경로를 구성하는 선과 곡선의 시퀀스가 저장되고 Pen 개체 및 GraphicsPath 개체는 DrawPath 메서드에 인수로 전달됩니다. 다음 예제에서는 선, 타원 및 3차원 곡선 스플라인으로 구성되는 경로를 그립니다.

        myGraphicsPath.AddLine(0, 0, 30, 20)
        myGraphicsPath.AddEllipse(20, 20, 20, 40)
        myGraphicsPath.AddBezier(30, 60, 70, 60, 50, 30, 100, 10)
        myGraphics.DrawPath(myPen, myGraphicsPath)

myGraphicsPath.AddLine(0, 0, 30, 20);
myGraphicsPath.AddEllipse(20, 20, 20, 40);
myGraphicsPath.AddBezier(30, 60, 70, 60, 50, 30, 100, 10);
myGraphics.DrawPath(myPen, myGraphicsPath);

다음 그림은 경로를 보여 줍니다.

경로

선, 사각형 및 곡선을 경로에 추가하는 것 외에 경로를 경로에 추가할 수 있습니다. 이 기능을 사용하면 기존 경로를 여러 개 조합하여 크고 복잡한 경로를 형성할 수 있습니다.

        myGraphicsPath.AddPath(graphicsPath1, False)
        myGraphicsPath.AddPath(graphicsPath2, False)

myGraphicsPath.AddPath(graphicsPath1, false);
myGraphicsPath.AddPath(graphicsPath2, false);

경로에 추가할 기타 항목으로 문자열과 원형이 있습니다. 원형은 타원 내부의 일부분입니다. 다음 예제에서는 원호, 카디널 스플라인, 문자열 및 원형에서 경로를 만듭니다.

        Dim myGraphicsPath As New GraphicsPath()

        Dim myPointArray As Point() = { _
           New Point(5, 30), _
           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.StartFigure()
        myGraphicsPath.AddCurve(myPointArray)
        myGraphicsPath.AddString("a string in a path", myFontFamily, _
           0, 24, myPointF, myStringFormat)
        myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110)
        myGraphics.DrawPath(myPen, myGraphicsPath)

     GraphicsPath myGraphicsPath = new GraphicsPath();

     Point[] myPointArray = {
new Point(5, 30), 
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.StartFigure();
     myGraphicsPath.AddCurve(myPointArray);
     myGraphicsPath.AddString("a string in a path", myFontFamily,
        0, 24, myPointF, myStringFormat);
     myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);
     myGraphics.DrawPath(myPen, myGraphicsPath);

다음 그림은 경로를 보여 줍니다. 경로는 반드시 연결될 필요가 없습니다. 원호, 카디널 스플라인, 문자열 및 원형은 분리되어 있습니다.

경로

참고 항목

작업

방법: 그리는 데 필요한 그래픽 개체 만들기

참조

System.Drawing.Drawing2D.GraphicsPath

System.Drawing.Point

기타 리소스

선, 곡선 및 도형

경로 구성 및 그리기