在Silverlight中旋转图像 [英] Rotate image smoothy in Silverlight
本文介绍了在Silverlight中旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网格,网格包含一个图像。网格在X轴上弯曲-52度。这是旋转但不顺利。
XAML代码是:
I have a grid and grid contains an image. Grid bent on -52 degree on X Axis. this is rotated but not smoothly.
XAML code is:
<grid x:name="LayoutRootNew" grid.row="0" grid.columnspan="3" grid.rowspan="3" margin="11,40,0,0" verticalalignment="Top" xmlns:x="#unknown">
<grid.projection>
<planeprojection rotationx="-51" />
</grid.projection>
<Image Name="imgArrow1" Source="@../../Images/circle31mar.png" Stretch="Uniform" UseLayoutRounding="True" Height="340" Width="340" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image.Projection>
<planeprojection x:name="Image1Projection" centerofrotationx="0.5" centerofrotationy="0.5" />
</Image.Projection>
<Image.RenderTransform>
<rotatetransform x:name="Prize_ListWheel_Rotate">
Angle="0" />
</Image.RenderTransform>
</Image>
<Image Name="imgArrow2" Source="@../../Images/FRRingNew3.png" Margin="0,0,0,0" Height="222" Width="225" HorizontalAlignment="Center">
<Image.Projection>
<planeprojection x:name="Image1Projection2" centerofrotationx="0.5" centerofrotationy="0.5" />
</Image.Projection>
</Image>
</rotatetransform></grid>
.cs代码为:
.cs code is:
_n = gameDataBO.FRRndNumber; //Animation for red black Wheel
SessionManager.newrandom = _n;
// _n = SessionManager.rnno;
//-----new work start---------
randomnumber = _n;
animanglerot = 360.0 / Convert.ToDouble(itextmaxcount);
anglesteps = Convert.ToInt64((itextmaxcount * 2 * numberofrotations - 38) * anglefactor);
//----------new work end---------
imgArrow1.RenderTransformOrigin = new Point(0.5, 0.5);
imgArrow1.RenderTransform = new RotateTransform();
da = new DoubleAnimation();
da.From = 0;
da.To = -anglesteps; //-360.00 * 1.9;// -(360.00 / 38.00);
anglesteps = anglesteps - 1;
Prize_ListWheel_Rotate.Angle += animanglerot / anglefactor;
//myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 300); // 100 Milliseconds
//myDispatcherTimer.Start();
da.Duration = TimeSpan.FromSeconds(2);
SineEase be = new SineEase();
be.EasingMode = EasingMode.EaseIn;
// da.EasingFunction = be;
_nRing = gameDataBO.FRRingRndNumber; //Animation for Ring
SessionManager.newringrandom = _nRing;
_nRing = SessionManager.ringno;
imgArrow2.RenderTransformOrigin = new Point(0.5, 0.5);
imgArrow2.RenderTransform = new RotateTransform();
da2 = new DoubleAnimation();
da2.From = 0;
da2.To = 360.00 * 1;// +(360.00 / 38.00);
da2.Duration = TimeSpan.FromSeconds(2);
// da2.EasingFunction = be;
_netRotation = (_n + _nRing);
if (_netRotation > 38)
{
_netRotation = (_netRotation % 38);
}
_finalAngle = _netRotation * (360.00 / 38.00);
Storyboard.SetTarget(da, imgArrow1.RenderTransform);
Storyboard.SetTarget(da2, imgArrow2.RenderTransform);
Storyboard.SetTargetProperty(da, new PropertyPath(RotateTransform.AngleProperty));
Storyboard.SetTargetProperty(da2, new PropertyPath(RotateTransform.AngleProperty));
sb1 = new Storyboard();
sb1.Children.Add(da);
sb1.Children.Add(da2);
sb1.Begin();
SessionManager.newsession = 0;
所以我想沿着X轴顺时针旋转那个图像,特定的时间段以不同的速度非常平滑。
这样可行但漫游不顺畅。我希望将图像旋转为平滑。请提供C#代码进行轮换。
so i want to rotate that image along X axis clock wise for particular time period with different speed very smooth.
This works but roration is not smooth. i want to rotate my image as smooth. Please provide C# code for rotation.
推荐答案
平滑度是生理性视网膜持久性的问题,对人类来说约为0.04s。
因此,如果你想在7秒内平稳地旋转你的图像,这意味着你必须确保最少的步数,在这种情况下将是steps = 7 / 0.04 = 175
。这意味着旋转角度最多360.0 / 175.0 = 2.057度
。
如果你遇到闪烁,那可能意味着两件事:
- 每一步都在大于0.04秒的时间内显示
- 或图形引擎无法显示顺利处理配置的旋转次数
Smoothness is a matter of physiological retinian persistance, which for humans is about 0.04s.
So if you want to rotate you image smoothly within 7 seconds, it means you have to ensure a minimum number of steps, which in this case would besteps = 7 / 0.04 = 175
. Which would mean a rotation angle of at most360.0 / 175.0 = 2.057 degrees
.
If you are experiencing flickering, that can mean two things:
- every step is displayed during a period larger than 0.04s
- or the graphic engine is not able to handle smoothly the number of rotations configured
这篇关于在Silverlight中旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文