【问题标题】:C# Simulating multitouch with KinectC# 使用 Kinect 模拟多点触控
【发布时间】:2012-07-12 08:45:25
【问题描述】:

我有一个 Kinect 应用程序,我可以生成 1-4 个不同的屏幕点(左手/右手最多 2 人),我希望能够将每个 Point 发送到应用程序,并将焦点作为多触摸消息。

我目前正在使用SendInput 发送鼠标移动、鼠标向下和鼠标向上消息,但是 AFAIK,它不支持 WM_TOUCH 消息。

有人知道在 C# 中发送多点触控消息的简单方法吗?作为测试,我希望能够在 MS Paint 中使用 Kinect,并用双手绘画(以及风的所有颜色)

【问题讨论】:

  • 谢谢,但是那个帖子谈到了鼠标消息,我需要发送触摸消息。您可以发送多个鼠标消息吗?这样我的屏幕上可以有多个鼠标吗?

标签: c# kinect multi-touch


【解决方案1】:

我认为这行不通,除非您通过将画布放下,然后在其顶部放置图像,然后是 4 个椭圆来保存每个人手的 x 和 y 坐标,例如: ,然后将它们的位置缩放到人们的关节,(请参阅Channel 9 了解如何执行此操作)。然后我会将坐标复制到double,然后设置它们的像素。这样做。

double person1hand1x = Canvas.GetLeft(person1hand1);
double person1hand1y =  Canvas.GetTop(person1hand1);

然后,我将使用 Image 控件根据这些操作更改画布的颜色。 System.Drawing 资源导入您的项目,您将需要它来设置像素 然后创建一个Bitmap 并将其像素设置为x 和y 所在的位置。这样做:

        Bitmap b = new Bitmap((int)image1.Width, (int)image1.Height); //set the max height and width

        b.SetPixel(person1hand1x, person1hand1y, person1hand1.Fill); //set the ellipse fill so they can keep track of who drew what


        image1.Source = ToBitmapSource(b); //convert to bitmap source... see https://stackoverflow.com/questions/94456/load-a-wpf-bitmapimage-from-a-system-drawing-bitmap/1470182#1470182 for more details
    }


    /// <summary>
    /// Converts a <see cref="System.Drawing.Bitmap"/> into a WPF <see cref="BitmapSource"/>.
    /// </summary>
    /// <remarks>Uses GDI to do the conversion. Hence the call to the marshalled DeleteObject.
    /// </remarks>
    /// <param name="source">The source bitmap.</param>
    /// <returns>A BitmapSource</returns>
    public static BitmapSource ToBitmapSource(this System.Drawing.Bitmap source)
    {
        BitmapSource bitSrc = null;

        var hBitmap = source.GetHbitmap();

        try
        {
            bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                hBitmap,
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());
        }
        catch (Win32Exception)
        {
            bitSrc = null;
        }
        finally
        {
            NativeMethods.DeleteObject(hBitmap);
        }

        return bitSrc;
    }

    internal static class NativeMethods
    {
        [DllImport("gdi32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool DeleteObject(IntPtr hObject);
    }

希望这会有所帮助! 注意:我从Load a WPF BitmapImage from a System.Drawing.Bitmap 得到了ToBitmapSource

【讨论】:

  • 感谢您的帖子!我已经有了每个附件的 X、Y 坐标,它们在屏幕坐标中。我实际上是在尝试将多点触控消息发送到具有焦点的应用程序。我不想重新创建绘画程序,我希望能够将我的 Kinect 变成一个通用的多点触控设备。
  • @joe_coolish 不可能拥有不止一只鼠标。如果这就是你所说的,那这幅画也只是一个例子吗?或者这就是你想要完成的事情
  • 只是一个例子。就像这个页面如何使用 MSPaint 作为多点触控显示器的测试一样:aperturering.hubpages.com/hub/MultiTouch-Test。最终目标是让 Kinect 成为 Multi Touch 设备
【解决方案2】:

你想要的是send messages 到有问题的窗口。您需要撰写的消息是WM_TOUCH 消息。您可以在 WM_TOUCH here 上找到一个非常有用的讨论主题。

希望这会有所帮助!

【讨论】:

  • 看起来很有希望!我将在下周尝试并接受如果这有助于我让它工作:)
  • 当然 - 如果您将这条消息指向的窗口的消息循环不使用 WM_TOUCH 消息,则不会发生任何事情 :)
  • 是的,如果应用程序不处理触摸消息,我将不得不对此进行测试,然后将鼠标作为主要附属物
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-12
  • 1970-01-01
  • 1970-01-01
  • 2011-06-05
  • 1970-01-01
  • 1970-01-01
  • 2013-04-11
相关资源
最近更新 更多