1

我期待着使用 c# 图形制作一个玫瑰花结......这是我想要实现的目标: 玫瑰花结

直到现在我这样做了:

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 个圆圈,但我只想显示中间那个包含玫瑰花的圆圈。如何摆脱主圈之外的那些额外行。如果有人可以给我一些代码行并告诉我这是如何完成的,我将不胜感激。

4

1 回答 1

0

从中心圆的矩形开始,然后按一定百分比对其进行 Inflate()。接下来,创建一个 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();

这是我完成的、剪裁好的玫瑰花结: 通过 Graphics.SetClip() 完成 Rosette

于 2013-05-06T20:00:59.717 回答