我如何可以旋转的的RectangleF在使用图形对象特定程度? [英] How can I rotate an RectangleF at a specific degree using Graphics object?
问题描述
我已经试过这样:
g.RotateTransform(度);
但没有happens.I有一个图形对象,并使用该方法的一个矩形对象女巫IM图:
g.FillRectangle(新的TextureBrush(Image.FromFile(@D:\ LOVE&放大器; LUA \图片\ yellowWool.png)),矩形);
和我需要以某种方式旋转矩形,然后重新绘制。
答与code样品,请与一个简单的解释。
编辑:这是我用实际code:
公共无效Draw(绘图克,的PointF位置,颜色clearColor)
{
rectangle.Location =位置;
g.Clear(clearColor);
g.RotateTransform(10);
//g.FillRectangle(new SolidBrush(彩色),矩形);
g.FillRectangle(新的TextureBrush(Image.FromFile(@D:\ LOVE&放大器; LUA \图片\ yellowWool.png)),矩形);
}
每个帧我把这种功能,我使用窗体的Paint事件的 e.Graphics
对象的图形和我有一个定时器
魔女只要求 this.Refresh();
编辑2:
好吧,我已经打了一个小有和 g.RotateTransform
旋转graphycs整个cordinate系统对象的变换,我需要在不改变cordinate系统只旋转矩形P>
您可以尝试使用与 RotateAt
方法的矩阵居中矩形围绕旋转:
使用(矩阵M =新的Matrix()){
m.RotateAt(10,新的PointF(rectangle.Left +(rectangle.Width / 2),
rectangle.Top +(rectangle.Height / 2)));
g.Transform =米;
使用(的TextureBrush TB =新的TextureBrush(Image.FromFile(@D:\ LOVE&放大器; LUA \图片\ yellowWool.png))
g.FillRectangle(TB,矩形);
g.ResetTransform();
}
在 ResetTransform()
会后把显卡恢复正常处理。
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
You can try using a matrix with the RotateAt
method to center the rotation around the rectangle:
using (Matrix m = new Matrix()) {
m.RotateAt(10, new PointF(rectangle.Left + (rectangle.Width / 2),
rectangle.Top + (rectangle.Height / 2)));
g.Transform = m;
using (TextureBrush tb = new TextureBrush(Image.FromFile(@"D:\LOVE&LUA\Pictures\yellowWool.png"))
g.FillRectangle(tb, rectangle);
g.ResetTransform();
}
The ResetTransform()
will turn the graphics back to normal processing after that.
这篇关于我如何可以旋转的的RectangleF在使用图形对象特定程度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!