GDI+의 그래픽 경로

경로는 선, 사각형, 단순 곡선을 결합하여 형성됩니다. 벡터 그래픽 개요에서 다음 기본 빌딩 블록이 그림을 그리는 데 가장 유용한 것으로 입증되었습니다.

  • 사각형

  • 타원

  • 원호

  • 다각형

  • 카디널 스플라인

  • 베지어 스플라인

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

직선에서 시작하여 다른 도형으로 계속되는 한 줄 경로의 이미지.

경로 사용

GraphicsPath 클래스는 그릴 항목 시퀀스를 만들기 위해 AddLine, AddRectangle, AddEllipse, AddArc, AddPolygon, AddCurve(카디널 스플라인의 경우), AddBezier 메서드를 제공합니다. 이러한 각 메서드는 오버로드됩니다. 즉, 각 메서드는 여러 매개 변수 목록을 지원합니다. 예를 들어 AddLine 메서드의 한 변형은 4개의 정수를 수신하고 AddLine 메서드의 다른 변형은 두 개의 Point 개체를 수신합니다.

경로에 선, 사각형, 베지어 스플라인을 추가하는 메서드에는 AddLines, AddRectangles, AddBeziers와 같이 단일 호출에서 경로에 여러 항목을 추가하는 복수의 도우미 메서드가 있습니다. 또한 AddCurveAddArc 메서드에는 경로에 닫힌 곡선 또는 원형을 추가하는 AddClosedCurveAddPie 도우미 메서드가 있습니다.

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

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)

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

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

다음 그림은 경로를 보여 줍니다. 경로를 연결할 필요는 없습니다. 호, 카디널 스플라인, 문자열, 원형은 구분됩니다.

경로

참고 항목