使用C#中的Matrix对象居中旋转的graphicPath

时间:2012-10-01 18:59:49

标签: c# matrix rotation

我正在编写一个库,它将创建一个graphihc路径(以多边形或矩形的形状)并旋转它,但我希望旋转的形状在其边界矩形中居中。我已经尝试了几乎所有的东西,以使形状在其中心旋转,但它在边缘切断。

下面是我为编写本文而编写的一些代码

        GraphicsPath path = new GraphicsPath();
        path.AddPolygon(new Point[] { new Point(0, 0), new Point(100, 0), new Point(100, 100), new Point(0, 100) });
        Matrix m = new Matrix();
        Matrix m2 = new Matrix();
        m2.Rotate(30);
        m.Translate(-((path.GetBounds(m2).Width) / 2), -((path.GetBounds(m2).Height) / 2));
        m.Rotate(30, MatrixOrder.Append);
        m.Translate(((path.GetBounds(m2).Width)/2), ((path.GetBounds(m2).Height)/2), MatrixOrder.Append);
        path.Transform(m);
        Bitmap b = new Bitmap((int)path.GetBounds().Width, (int)path.GetBounds().Height);
        Graphics g = Graphics.FromImage(b);

        g.FillPath(Brushes.Blue, path);

        b.Save(@"c:\aSSETS\sample3.png");

请帮忙。感谢

0 个答案:

没有答案