如何检查手指是否移动了图像? (操作)

时间:2019-04-16 09:40:28

标签: c# wpf

我已经在处理画布上的图像了。现在,我需要检查图像是否在手指上移动了。该怎么做?

     void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {            
            Image photoToMove = e.OriginalSource as Image;
            int photoIndex = photos.IndexOf(photoToMove);            

            System.Windows.Media.Matrix rectsMatrix = ((MatrixTransform)photoToMove.RenderTransform).Matrix;
            rectsMatrix.RotateAt(e.DeltaManipulation.Rotation,
                                 e.ManipulationOrigin.X,
                                 e.ManipulationOrigin.Y);
            rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                                e.DeltaManipulation.Scale.X,
                                e.ManipulationOrigin.X,
                                e.ManipulationOrigin.Y);
            rectsMatrix.Translate(e.DeltaManipulation.Translation.X,
                                  e.DeltaManipulation.Translation.Y);
            MatrixTransform newImageMTransform = new MatrixTransform(rectsMatrix);
            photoToMove.RenderTransform = newImageMTransform;

            Rect containingRect =
                new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize);

            Rect shapeBounds =
                photoToMove.RenderTransform.TransformBounds(
                    new Rect(photoToMove.RenderSize));

            if (e.IsInertial && !containingRect.Contains(shapeBounds))
            {
                e.Complete();
            }

            if (e.DeltaManipulation.Translation.X > 0 || e.DeltaManipulation.Translation.Y > 0)
            {
                imageMoved = true;
            }
            else
            {
                imageMoved = false;
            }          

            e.Handled = true;

        }

现在,这段代码总是告诉我“ imageMoved == true”。

0 个答案:

没有答案