【问题标题】:exact String check (WPF Multitouch)精确的字符串检查(WPF 多点触控)
【发布时间】:2010-12-25 15:27:37
【问题描述】:

我试图首先让你进入画面,我试图在 WPF4 VS2010 中实现一个手势,就像你移动你的手指直到它穿过你已经用相同的手指经过的接触点,所以我的想法是制作一个列表并检查每个新的接触点是否存在,如果是,那么你已经完成了你的手势,如果没有,那么将接触点添加到集合中以与以下接触点进行比较。出于某种原因,这不能很好地工作,所以我转向了另一种方法,用 X 替换 TouchPoints , Y 为 TouchPoint 并将它们转换为字符串并尝试对它们使用 Contains 方法,使用 TouchMove 和 TouchUp 事件我的代码看起来像:

 private void g1_TouchMove(object sender, TouchEventArgs e)
    {



       if(touchX.Contains(""+e.GetTouchPoint(g1).Position.X) && touchY.Contains(""+e.GetTouchPoint(g1).Position.Y))
        {
         // Clearing the lists , changing the canvas background color to know that the gesture is done
           touchX.Clear();
           touchY.Clear();
           g1.Background = Brushes.AliceBlue;

        }
       else
       {
           //adding new X, Y values to their respective lists
           touchX.Add(""+e.GetTouchPoint(g1).Position.X);
           touchY.Add( ""+e.GetTouchPoint(g1).Position.Y);


       }

    }
private void g1_TouchUp(object sender, TouchEventArgs e)
    {
        //clearing the lists after the touch is up (finger removed)
        touchX.Clear();
        touchY.Clear();
        //getting the canvas it's original background color
        g1.Background = Brushes.Orange;

    }

所以,在测试它时它不起作用,即使我沿直线移动触摸它也会改变背景。有什么想法吗?

提前致谢

【问题讨论】:

    标签: c# wpf string contains multi-touch


    【解决方案1】:

    首先,回到使用数字。将数字放入字符串中以供以后比较在很多层面上都是错误的:-)

    我的猜测是您的问题是分辨率问题 - 几乎不可能像以前一样到达完全相同的位置,因为有很多 em> 屏幕上的像素。基本上,减少一个像素将使您的算法无用。相反,您应该将您的触摸区域映射到几个较大的簇中,并检查触摸之前是否在该簇中(而不是完全相同的像素)。

    一种简单的方法是对收到的坐标进行整数除法。

    在下面的示例中,我将像素坐标系划分为 3 x 3 像素的集群,但如果这对您有意义,您可以选择更大的。这完全取决于触摸区域的分辨率有多大。

    这实际上意味着这 3 x 3 区域内的任何像素都被认为是相等的。因此,(1,1) 上的命中与 (2,3) 上的先前命中相匹配,依此类推。

    // Divide into 3x3 pixel clusters
    var currentCluster = new Point((int)touchPos.X / 3, (int)touchPos.Y / 3)
    // previousClusters is a List<Point>() which is cleared on TouchUp
    foreach (var cluster in previousClusters)
    {
        if (cluster == currentCluster)
        {
            // We've been here before, do your magic here!
            g1.Background = Brushes.AliceBlue;
            // Return here, since we don't want to add the point again
            return;
        }
    }
    previousClusters.Add(currentCluster);
    

    【讨论】:

    • 非常感谢 Isak 先生,尚未对其进行测试,但似乎这就是我想要的,是的,我真的不知道为什么我将数字更改为字符串以进行比较,不好意思,再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 2013-05-07
    相关资源
    最近更新 更多