使用Rotatetransform时控制是闪烁的 [英] Control is Flickering while using Rotatetransform

查看:144
本文介绍了使用Rotatetransform时控制是闪烁的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在使用WPF应用程序,我在Ellipse上添加了Ellipse和Thumbs。当拇指移动时,我正在计算该拇指与中心点的角度并旋转画布的所有孩子。但在旋转时它会闪烁。请查看以下代码
并提供任何解决方案,



  private void OnKeyPointThumbDragDelta(object sender,System.Windows.Controls .Primitives.DragDeltaEventArgs e)

{


                GetAngleCurvePoint(thumb.Position,e.Horizo​​ntalChange,e.VerticalChange,out var angle);


                VisualTransform = new TransformGroup

                {

                       儿童=

                        {

                           新的RotateTransform(角度,CenterPoint.X,CenterPoint.Y),

                        }¥b $ b                };

}



私人Point GetAngleCurvePoint(点数,双eHorizo​​ntalChange,双eVerticalChange,out double angle)

        {

            var newLocation = new Point(point.X + eHorizo​​ntalChange,point.Y + eVerticalChange);

            var yDiff = newLocation.Y - CenterPoint.Y;

            var xDiff = newLocation.X - CenterPoint.X;

            angle = Math.Atan2(yDiff,xDiff)* 180.0 / Math.PI;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(角度< 0)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;角度+ = 360;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;角度+ = 180;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //角度+ = 180;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var x =(XDiameter-0.5 + AngleGap)/ 2 * Math.Cos(angle * Math.PI / 180)+ CenterPoint.X;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var y =(YDiameter-0.5 + AngleGap)/ 2 * Math.Sin(angle * Math.PI / 180)+ CenterPoint.Y;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新点(x,y);



  &NBSP; &NBSP; &NBSP; }

解决方案

嗨  &NBSP; SantoshVB,




>>我正在使用WPF应用程序添加了Ellipse椭圆上的拇指和拇指。当拇指移动时,我正在计算该拇指与中心点的角度并旋转画布的所有孩子。但是当旋转
时它会闪烁。




根据您提供的代码,我们无法重现你的问题。请上传正在运行的演示。我们可以下载它并进行调试。这有助于我们快速分析您的问题。
b


此外,您的问题与性能问题有关,最好是收集数据,我们可以优化代码。我们需要找出性能问题的原因,然后通过我们的确认来解决这些问题。



我建议您通过WPF Performance Tool测试动画并检查哪个元素/块花了很多时间。请参阅此
关于WPF性能工具的文章: 
$


$
以下文章供您参考。



WPF性能问题解决方案





最好的问候,



Yong Lu


Hello,

I am using WPF application where I have added Ellipse and Thumbs on Ellipse. When thumb moves I am calculating angle of that thumb with center point and rotating all children of Canvas. But while rotating it its flickering. Kindly look into following code and provide any solution,

 private void OnKeyPointThumbDragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{

               GetAngleCurvePoint(thumb.Position, e.HorizontalChange, e.VerticalChange, out var angle);

                VisualTransform = new TransformGroup
                {
                        Children =
                        {
                            new RotateTransform(angle, CenterPoint.X, CenterPoint.Y),
                        }
                };

}

private Point GetAngleCurvePoint(Point point, double eHorizontalChange, double eVerticalChange, out double angle)
        {
            var newLocation = new Point(point.X + eHorizontalChange, point.Y + eVerticalChange);
            var yDiff = newLocation.Y - CenterPoint.Y;
            var xDiff = newLocation.X - CenterPoint.X;
            angle = Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI;
            if (angle < 0)
            {
                angle += 360;
            }

            angle += 180;
            //angle += 180;

            var x = (XDiameter-0.5 + AngleGap) / 2 * Math.Cos(angle * Math.PI / 180) + CenterPoint.X;
            var y = (YDiameter-0.5 + AngleGap) / 2 * Math.Sin(angle * Math.PI / 180) + CenterPoint.Y;

            return new Point(x, y);

        }

解决方案

Hi    SantoshVB,


>>I am using WPF application where I have added Ellipse and Thumbs on Ellipse. When thumb moves I am calculating angle of that thumb with center point and rotating all children of Canvas. But while rotating it its flickering.


According to the code you provided, we can not reproduce your problem. Please upload a running demo. We can download it and debugging. This will help us quickly analyze your problem.

Besides, your issue is regarding to the performance issue, it is better to collect the data and we could optimize the code. We need to find out the reasons of performance issue then resolve these issues with our acknowledges.

I suggest you test the animation by WPF Performance Tool and check which element/block spends much time. Please refer to this article about WPF Performance Tool: 


The following articles for your reference.

Solutions for WPF Performance Issue


Best Regards,

Yong Lu


这篇关于使用Rotatetransform时控制是闪烁的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆