다음을 통해 공유


방법: 열린 그림 채우기

GraphicsPath 개체를 FillPath 메서드에 전달하여 경로를 채울 수 있습니다. FillPath 메서드에서는 경로에 현재 설정되어 있는 채우기 모드(alternate 또는 winding)에 따라 경로를 채웁니다. 경로에 열린 그림이 있으면 이 그림이 닫혀 있는 것처럼 경로가 채워집니다. 즉, GDI+에서는 끝점과 시작점을 직선으로 연결하여 열린 그림을 닫습니다.

예제

아래 예제에서는 열린 그림 하나(원호)와 닫힌 그림 하나(타원)로 이루어진 경로를 만듭니다. FillPath 메서드는 기본 채우기 모드인 Alternate에 따라 경로를 채웁니다.

다음 그림은 예제 코드의 실행 결과를 보여 줍니다. 여기에서는 열린 그림의 끝점과 시작점을 직선으로 연결하여 이 그림이 닫혀 있는 것처럼 경로를 채웁니다(Alternate 모드 사용).

열린 경로 채우기

        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)

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

코드 컴파일

앞의 예제는 Windows Forms에서 사용해야 하며 Paint 이벤트 처리기의 매개 변수인 PaintEventArgs e를 필요로 합니다.

참고 항목

참조

GraphicsPath

개념

GDI+의 그래픽 경로