怎么画玫瑰花?

时间:2013-05-06 19:22:19

标签: c# graphics drawing

我期待用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个圆圈,但我只想显示包含rossete的中间的圆圈。如何摆脱主圈外的那些额外线条.. 如果有人可以给我一些代码并告诉我这是如何完成的,我会很感激。

1 个答案:

答案 0 :(得分:0)

从中心圆的矩形开始,按一定百分比膨胀()。接下来,创建一个GraphicsPath()并使用膨胀的矩形通过AddEllipse()为其添加一个椭圆。最后,使用SetClip()CLIP您的图形表面。这样可以防止显示椭圆外的任何内容:

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