Kinect-根据用户与kinect传感器的距离来更改字体大小

时间:2019-04-01 11:34:16

标签: c# kinect

我正在使用Kinect进行项目,我需要根据用户距Kinect传感器的距离来更改文本的大小。这意味着,如果用户将走近传感器,则文本的字体大小将变小。然后,如果用户离开传感器,字体大小将变大。

所以我在互联网上的某个地方找到了此代码,这正是我所需要的。至少我希望这是我所需要的。我没有设法使它起作用:

 private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
    {
        bool dataReceived = false;

        using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
        {
            if (bodyFrame != null)
            {
                if (bodies == null)
                {
                    bodies = new Body[bodyFrame.BodyCount];
                }

                bodyFrame.GetAndRefreshBodyData(bodies);
                dataReceived = true;
            }
        }
        if (dataReceived)
        {
            var trackedMe = bodies.Where(bodies => bodies.IsTracked).FirstOrDefault(); //added using System.Linq; because of Where
            if (trackedMe == null) return;

            IReadOnlyDictionary<JointType, Joint> joints = trackedMe.Joints;
            var head = joints[JointType.Head];
            if (head.TrackingState == TrackingState.Tracked)
            {
                var position = head.Position;
                //MeDistance = position.Z.ToString();
                double dist = Math.Sqrt(position.X * position.X + position.Y * position.Y + position.Z * position.Z);
                dist.ToString();
                MyDistance = dist;
            }
        }
    }

    public string MeDistance
    {
        get
        {
            return meDistance;
        }

        set
        {
            if (meDistance != value)
            {
                meDistance = value;
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs("MeDistance"));
                    this.PropertyChanged(this, new PropertyChangedEventArgs("MyFontSize"));
                }
            }
        }
    }

    public int MyFontSize
    {
        get
        {
            float distance;
            var result = float.TryParse(MeDistance, out distance);                    
            if (result)
            {
                return (int)(distance * 20);
            }
            return 16;
        }
    }

字体大小完全不变,并且始终为16。我知道为什么是16,但是我不知道如何更改它。

非常感谢

编辑:Okey,我用完全不同的解决方案解决了这个问题。

0 个答案:

没有答案