C#使用Kinect模拟多点触控
我有一个Kinect应用程序,我可以生成1-4个不同的屏幕点(左手/右手最多2人),我希望能够将每个Point
发送到应用程序,焦点作为多点触摸消息。
我目前正在使用SendInput
发送鼠标移动,鼠标按下和鼠标按下消息,但是AFAIK,它不支持WM_TOUCH
消息。
有谁知道在C#中发送多点触控消息的简单方法? 作为测试,我希望能够在MS Paint中使用Kinect,并用双手绘画(以及风的所有颜色)
你想要的是发送消息到相关的窗口。 您需要撰写的消息是WM_TOUCH
消息。 你可以在WM_TOUCH
上找到一个非常有用的讨论主题。
希望这可以帮助!
我不认为这会有效,除非你做了一些保存每个人手的x和y的坐标,通过放下canvas,然后在它上面的图像,然后是4个椭圆,如: ,然后将它们的位置缩放到人体关节,(有关如何执行此操作,请参阅第9频道 )。 然后我会将坐标复制到一个double
,然后设置它们的像素。 这样做。
double person1hand1x = Canvas.GetLeft(person1hand1); double person1hand1y = Canvas.GetTop(person1hand1);
然后我将使用Image控件根据这些操作更改canvas的颜色。 将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 } /// /// Converts a into a WPF . /// /// Uses GDI to do the conversion. Hence the call to the marshalled DeleteObject. /// /// The source bitmap. /// A BitmapSource 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); }
希望这可以帮助! 注意:我从System.Drawing.Bitmap加载了一个来自WPF BitmapImage的ToBitmapSource