2017-05-02 2 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; 
    } 

は、しかし、私は私が望んでいた結果を得ることはありません、コーナーのそれぞれは、下の画像に見られるように、そのピクセルのずれのいずれかが一致しないです。
Bottom left corner of rounded rectangle Top left corner of rounded rectangle
Top right corner of rounded rectangle Bottom right 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 +が描画された図形を1つの連続した図形として表示しないため、図形を塗り潰したい場合などはできません。

この点についてはGraphicsPathを使用してください。

drawing rounded rectangles using a GraphicsPathの完全な解決方法については、こちらを参照してください。

関連する問題