我有一个在WinForms中绘制和编辑矢量图形的应用程序
我有图像,矩形,椭圆,区域等,我知道如何通过鼠标移动调整它们的大小。但我不知道如何通过鼠标移动来旋转它们。
我将对象绘制到图形中。
我试过了,但不起作用。
g.TranslateTransform((float)(this.Rectangle.X + this.Rectangle.Width / 2), (float)(this.Rectangle.Y + this.Rectangle.Height / 2));
g.RotateTransform(this.Rotation);
g.TranslateTransform(-(float)(this.Rectangle.X + this.Rectangle.Width / 2), -(float)(this.Rectangle.Y + this.Rectangle.Height / 2));
//g.TranslateTransform(-(float)(rect.X + rect.Width / 2), -(float)(rect.Y + rect.Height / 2));
g.DrawImage(img, rect);
g.ResetTransform();这不起作用,因为我不知道如何在新的(旋转的)位置找到对象的角落,所以我无法调整它的大小…
发布于 2012-02-01 00:31:08
你需要应用高中的三角学。如果你在谷歌上搜索"graphics.drawimage rotation“,有很多文章。
但首先,您不应该转换Graphics对象本身。您只是希望获得图像的新边界框。为此,请执行以下操作:
Point[] boundingBox ={ new Point(-width/2,- height/2),new Point(width/2,-height/2),new Point(-width /2,height/2)};
Point rotatePointAroundOrigin(Point point,float angleInDegrees) { float angle = angleInDegrees * Math.PI/180;//以弧度表示的获取角度返回新Point( point.X *Math.Cos(角度)- point.Y *Math.Sin(角度),point.X *Math.Sin(角度)+ point.Y *Math.Cos(角度));}
DrawImage(image, boundingBox)https://stackoverflow.com/questions/9080742
复制相似问题