日期:2014-05-17  浏览次数:20882 次

对Rectangle旋转了下,但是它的坐标仍然是之前的坐标,怎么获得旋转后的坐标?

对Rectangle旋转了下,但是它的坐标仍然是之前的坐标,怎么获得旋转后的坐标?
代码如下:
                //要绘制的矩形
                var picRect = new RectangleF(RationPoint.X, RationPoint.Y, (float)innerWidth, (float)innerHeight);
                 Pcenter = new PointF(picRect.X + picRect.Width/2, picRect.Y + picRect.Height/2);
                //绘图平面以图片的中心点旋转
                graphics.TranslateTransform(Pcenter.X, Pcenter.Y);
                graphics.RotateTransform(_ShapeExAngle);
                //恢复绘图平面在水平和垂直方向的平移
                graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y);

               //绘制图片
                graphics.DrawRectangle(borderPen, Rectangle.Ceiling(picRect));
                //重置绘图平面的所有变换
                graphics.ResetTransform();




------解决方案--------------------

PointF[] points = new PointF[] {  // 将原来四边形的4个顶点坐标放入数组
 picRect.Location,
 new PointF(picRect.Right, picRect.Top),
 new PointF(picRect.Right, picRect.Bottom),
 new PointF(picRect.Left, picRect.Bottom)
};  
graphics.Transform.TransformPoints(points); // 利用已经在Graphics上的变换对坐标进行转换

// 转换之后,points数组中的值就是你要的值,然后就看你自己的了。



如果不想对Graphics进行变换,可以直接使用Matrix类,它的使用方法与在Graphics里基本相同,具体使用方式可参考MSDN的说明。