2013-05-06 62 views
1

我期待着做一個花環使用C#圖形... 這裏是我想要實現: Rosette如何畫玫瑰花?

直到現在我這樣做:

Pen lapsi = new Pen(Color.Black, 3); 

     Rectangle katrori = new Rectangle(250, 200, 200, 200); 
     Rectangle katrori2 = new Rectangle(350, 200, 200, 200); 
     Rectangle katrori3 = new Rectangle(150, 200, 200, 200); 

     Rectangle katrori4 = new Rectangle(200, 110, 200, 200); 
     Rectangle katrori5 = new Rectangle(200, 285, 200, 200); 
     Rectangle katrori6 = new Rectangle(295, 110, 200, 200); 
     Rectangle katrori7 = new Rectangle(300, 282, 200, 200); 

     Graphics g = this.CreateGraphics(); 

     g.DrawEllipse(lapsi, katrori); //kryesor 
     g.DrawEllipse(lapsi, katrori2); //djatht 
     g.DrawEllipse(lapsi, katrori3); //majt 
     g.DrawEllipse(lapsi, katrori4); //nalt-majt 
     g.DrawEllipse(lapsi, katrori5); //posht-majt 
     g.DrawEllipse(lapsi, katrori6); //nalt-djatht 
     g.DrawEllipse(lapsi, katrori7);//posht djatht 

我畫7到目前爲止,但我只想顯示在中間包含羅斯特的一個。如何擺脫主圈外的那些額外的線.. 如果有人可以給我一些代碼行,並告訴我這是如何完成的,我會很感激。

+0

這是一個C#的問題,不是一個C的問題。相應地重新標記。 – 2013-05-06 19:23:46

+0

意外地按下輸入,ty :) – Kastriot 2013-05-06 19:29:41

回答

0

從您的中心圓的矩形開始,並按某個百分比膨脹()。接下來,創建一個GraphicsPath()並通過AddEllipse()使用膨脹的矩形添加一個橢圓。最後,使用SetClip()來裁剪圖形表面。這將防止正在顯示橢圓形以外的任何東西:

 Pen lapsi = new Pen(Color.Black, 3); 

     Rectangle katrori = new Rectangle(250, 200, 200, 200); 
     Rectangle katrori2 = new Rectangle(350, 200, 200, 200); 
     Rectangle katrori3 = new Rectangle(150, 200, 200, 200); 

     Rectangle katrori4 = new Rectangle(200, 110, 200, 200); 
     Rectangle katrori5 = new Rectangle(200, 285, 200, 200); 
     Rectangle katrori6 = new Rectangle(295, 110, 200, 200); 
     Rectangle katrori7 = new Rectangle(300, 282, 200, 200); 

     Graphics g = this.CreateGraphics(); 

     Rectangle clippingRectangle = new Rectangle(katrori.Location, katrori.Size); 
     clippingRectangle.Inflate((int)(katrori.Width * .2), (int)(katrori.Width * .2)); 
     System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath(); 
     GP.AddEllipse(clippingRectangle); 
     g.SetClip(GP); 

     g.DrawEllipse(lapsi, katrori); //kryesor 
     g.DrawEllipse(lapsi, katrori2); //djatht 
     g.DrawEllipse(lapsi, katrori3); //majt 
     g.DrawEllipse(lapsi, katrori4); //nalt-majt 
     g.DrawEllipse(lapsi, katrori5); //posht-majt 
     g.DrawEllipse(lapsi, katrori6); //nalt-djatht 
     g.DrawEllipse(lapsi, katrori7);//posht djatht 

     g.Dispose(); 

這裏是我完成的,修剪玫瑰花: Finished Rosette via Graphics.SetClip()

+0

它的工作,我從中學到了... 謝謝 – Kastriot 2013-05-06 21:50:20