gpt4 book ai didi

c# - Graphics.RotateTransform() 在绘制图像后仍然存在

转载 作者:太空宇宙 更新时间:2023-11-03 23:16:38 24 4
gpt4 key购买 nike

编写包含一些图形的 WinForms 应用程序。要旋转图像,我使用 e.Graphics.RotateTransform(angle) 方法,然后绘制图像。几行之后,我调用了 e.Graphics.RotateTransform(0) 以便我没有旋转其他图像并且应该正常显示。然而,情况并非如此,似乎我之后绘制的所有内容都受到相同变换的影响。为什么 RotateTransform(0) 不重置页面的 Transform 以恢复正常?

注意:这是我代码中 _Paint 事件的结果,但这是问题所在。我已尝试包含任何可能相关的内容

e.Graphics.TranslateTransform(Chute1Rect.Width / 2 + Chute1Rect.X, Chute1Rect.Height / 2 + Chute1Rect.Y);

if (increasing) //Chute is rotating out of the way
{
e.Graphics.RotateTransform(chuteAngle);

e.Graphics.TranslateTransform(-1 * (Chute1Rect.Width / 2 + Chute1Rect.X), -1 * (Chute1Rect.Height / 2 + Chute1Rect.Y));
e.Graphics.DrawImage(ChuteRotating, Chute1Rect);

//These statements do not seem to be resetting the graphics drawing by the time we do the trains
e.Graphics.TranslateTransform(Chute1Rect.Width / 2 + Chute1Rect.X, Chute1Rect.Height / 2 + Chute1Rect.Y);
e.Graphics.RotateTransform(0);
}
else //Chute is rotating into load position
{
if (chuteAngle == 0) //Chute has rotated into load position
{
e.Graphics.TranslateTransform(-1 * (Chute1Rect.Width / 2 + Chute1Rect.X), -1 * (Chute1Rect.Height / 2 + Chute1Rect.Y));

//Getting here means that the chute can be lifted & lowered because we are rotated down
if (lifting) //Chute is lifting out of the way
{
Chute1SlideRect.Y -= chuteDistance;
Chute2SlideRect.Y -= chuteDistance;

e.Graphics.DrawImage(ChuteSlide, Chute1SlideRect);
e.Graphics.DrawImage(ChuteSlide, Chute2SlideRect);
}
else //Chute is lifting into load position
{
Chute1SlideRect.Y -= chuteDistance;
Chute2SlideRect.Y -= chuteDistance;

e.Graphics.DrawImage(ChuteSlide, Chute1SlideRect);
e.Graphics.DrawImage(ChuteSlide, Chute2SlideRect);
}

e.Graphics.DrawImage(ChuteJoint, Chute1JointRect);
e.Graphics.DrawImage(ChuteJoint, Chute2JointRect);
}
else
{
e.Graphics.RotateTransform(chuteAngle);

e.Graphics.TranslateTransform(-1 * (Chute1Rect.Width / 2 + Chute1Rect.X), -1 * (Chute1Rect.Height / 2 + Chute1Rect.Y));
e.Graphics.DrawImage(ChuteRotating, Chute1Rect);

//These statements do not seem to be resetting the graphics drawing by the time we do the trains
e.Graphics.TranslateTransform(Chute1Rect.Width / 2 + Chute1Rect.X, Chute1Rect.Height / 2 + Chute1Rect.Y);
e.Graphics.RotateTransform(0);
}
}
//Down below here is where the trains get drawn

最佳答案

MSDN docs没有明确说明这一点,但似乎 RotateTransform 总是修改现有的变换矩阵,在这种情况下 RotateTransform(0) 意味着“什么都不做”而不是“设置旋转回到0。”尝试以与初始角度相反的角度旋转它。

编辑:或使用 ResetTransform() ( docs ) 使事情回到开始的地方,然后从那里开始。

关于c# - Graphics.RotateTransform() 在绘制图像后仍然存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37038080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com