如何使用 Graphics 对象将 RectangleF 旋转特定角度?
我已经尝试过这个:
g.RotateTransform(degrees);
但没有任何反应。我有一个图形对象和一个矩形对象,我使用这种方法进行绘制:
g.FillRectangle(new TextureBrush(Image.FromFile(@"D:\LOVE&LUA\Pictures\yellowWool.png")), rectangle);
并且我需要以某种方式旋转矩形并再次绘制它。
请用代码示例回答并进行简单的解释。
编辑:这是我正在使用的实际代码:
public void Draw(Graphics g,PointF location,Color clearColor)
{
rectangle.Location = location;
g.Clear(clearColor);
g.RotateTransform(10);
//g.FillRectangle(new SolidBrush(Color), rectangle);
g.FillRectangle(new TextureBrush(Image.FromFile(@"D:\LOVE&LUA\Pictures\yellowWool.png")), rectangle);
}
每个帧我都调用此函数,并且我使用表单的 Paint 事件的 e.Graphics
对象作为图形,并且我有一个 计时器 女巫只调用
this.Refresh();
编辑 2: 好的,我玩了一下转换,g.RotateTransform
旋转 graphycs 对象的整个坐标系,我只需要旋转矩形而不更改坐标系
I have tried this:
g.RotateTransform(degrees);
But nothing happens.I have one graphics object and one rectangle object witch im drawing using this method:
g.FillRectangle(new TextureBrush(Image.FromFile(@"D:\LOVE&LUA\Pictures\yellowWool.png")), rectangle);
And i need to rotate the rectangle somehow and draw it again.
Answer with code sample please and with a simple explanation.
EDIT: Here is the actual code I'm using:
public void Draw(Graphics g,PointF location,Color clearColor)
{
rectangle.Location = location;
g.Clear(clearColor);
g.RotateTransform(10);
//g.FillRectangle(new SolidBrush(Color), rectangle);
g.FillRectangle(new TextureBrush(Image.FromFile(@"D:\LOVE&LUA\Pictures\yellowWool.png")), rectangle);
}
Each frame I call this function and I'm using form's Paint event's e.Graphics
object for the Graphics and i have a timer
witch only calls this.Refresh();
EDIT 2:
OK I have played a little with the transformations and g.RotateTransform
rotates the whole cordinate system of the graphycs object and i need to rotate only the rectangle without changing the cordinate system
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用带有
RotateAt
方法的矩阵来使旋转围绕矩形居中:之后
ResetTransform()
会将图形恢复到正常处理。You can try using a matrix with the
RotateAt
method to center the rotation around the rectangle:The
ResetTransform()
will turn the graphics back to normal processing after that.