2017-05-02 1 views
0

여기에 정의 된 둥근 사각형 확장 방법을 구현했습니다. 내가 그렇게 g.DrawRRectangle(p, 100, 100, 1000, 1000, 100);, 처럼이 방법을 사용하면다른 그림에 베 지어 곡선 결합하기

public static Graphics DrawRRectangle(this Graphics g, Pen p, int x, int y, int width, int height, int feathering) 
    { 
     g.DrawLine(p, x, y + feathering, x, y + height - feathering); 
     g.DrawBezier(p, new Point(x, y + height - feathering), 
         new Point(x, y + height - feathering/2), new Point(x + feathering/2, y + height), 
         new Point(x + feathering, y + height)); 

     g.DrawLine(p, x + feathering, y + height , x + width - feathering, y + height); 
     g.DrawBezier(p, new Point(x + width - feathering, y + height), 
         new Point(x + width - feathering/2, y + height), new Point(x + width, y + height - feathering/2), 
         new Point(x + width, y + height - feathering)); 

     g.DrawLine(p, x + width, y + height - feathering, x + width, y + feathering); 
     g.DrawBezier(p, new Point(x + width, y + feathering), 
         new Point(x + width, y + feathering/2), new Point(x + width - feathering/2, y), 
         new Point(x + width - feathering, y)); 

     g.DrawLine(p, x + width - feathering, y, x + feathering, y); 
     g.DrawBezier(p, new Point(x + feathering, y), 
         new Point(x + feathering/2, y), new Point(x, y + feathering/2), 
         new Point(x, y + feathering)); 
     return g; 
    } 

그러나 나는 내가 원하는 결과를 얻을하지 않습니다 모서리의 각은 아래 이미지에서 볼 수 있듯이 자신의 픽셀의 잘못 정렬 중 하나가 일치하지 않을 수 있습니다. 이 그러나 이것이 내가 취미 삼아하고 처음 내 곡선을 생성하는 데 사용되는 방정식에 문제가있는 경우
Top right corner of rounded rectangle Bottom right corner of rounded rectangle

사람이 도움이 될 것입니다 제공 할 수있는 모든 제안
Bottom left corner of rounded rectangle Top left corner of rounded rectangle , 나는 확실하지 오전 그래픽으로, 그래서 내 생각 일 수 있습니다. 감사.

+0

둥근 사각형을 그릴 때 더 좋은 방법이 있습니다 ... – series0ne

+0

https://web.archive.org/web/20111110163706/http://www.switchonthecode.com/tutorials/csharp-creating-rounded-rectangles-using -a-graphics-path – series0ne

+0

http://stackoverflow.com/questions/19167463/oddly-drawn-graphicspath-with-graphics-fillpath – series0ne

답변

2

구현에 대해 의견을 말할 수는 없지만 이와 관련하여 문제가 계속 될 것입니다. 귀하의 구현은 둥근 사각형 그리기의 외관을 제공하지만, 예를 들어 나중에 GDI/GDI +가 하나의 연속 된 모양으로 그려진 모양을 보지 않기 때문에 나중에 모양을 채우기를 원한다고 말할 수 있습니다.

이와 관련하여 GraphicsPath을 사용해야합니다.

drawing rounded rectangles using a GraphicsPath에 대한 완벽한 해결책은 여기를 참조하십시오.