방법: 열린 그림 채우기

FillPath 메서드에 GraphicsPath 개체를 전달하여 경로를 채울 수 있습니다. FillPath 메서드는 현재 경로에 대해 설정된 채우기 모드(대체 또는 권선)에 따라 경로를 채웁니다. 경로에 열려 있는 그림이 있으면 해당 그림이 닫힌 것처럼 경로가 채워집니다. GDI+는 끝점에서 시작점으로 직선을 그려 그림을 닫습니다.

예제

다음 예제에서는 열려 있는 그림 하나(호)와 닫힌 그림 하나(타원)가 있는 경로를 만듭니다. FillPath 메서드는 기본 채우기 모드(예: Alternate)에 따라 경로를 채웁니다.

다음 그림에서는 예제 코드의 출력을 보여 줍니다. 열린 그림이 끝점에서 시작점까지 직선으로 닫힌 것처럼 경로가 채워집니다(Alternate에 따라).

FillPath 메서드의 출력을 보여주는 다이어그램

GraphicsPath path = new GraphicsPath();

// Add an open figure.
path.AddArc(0, 0, 150, 120, 30, 120);

// Add an intrinsically closed figure.
path.AddEllipse(50, 50, 50, 100);

Pen pen = new Pen(Color.FromArgb(128, 0, 0, 255), 5);
SolidBrush brush = new SolidBrush(Color.Red);

// The fill mode is FillMode.Alternate by default.
e.Graphics.FillPath(brush, path);
e.Graphics.DrawPath(pen, path);
Dim path As New GraphicsPath()

' Add an open figure.
path.AddArc(0, 0, 150, 120, 30, 120)

' Add an intrinsically closed figure.
path.AddEllipse(50, 50, 50, 100)

Dim pen As New Pen(Color.FromArgb(128, 0, 0, 255), 5)
Dim brush As New SolidBrush(Color.Red)

' The fill mode is FillMode.Alternate by default.
e.Graphics.FillPath(brush, path)
e.Graphics.DrawPath(pen, path)

코드 컴파일

앞의 예제는 Windows forms에서 사용하도록 설계되었으며 PaintEventArgs 이벤트 처리기의 매개 변수인 ePaint가 필요합니다.

참고 항목