C# Simulating multitouch with Kinect

我怕爱的太早我们不能终老 提交于 2019-11-29 11:08:56
Ani

What you want is to send messages to the window in question. The message you need to compose is the WM_TOUCH message. You can find a very helpful discussion thread on WM_TOUCH here.

Hope this helps!

Liam McInroy

I don't think this would work, unless you did something with saving the coordinates of the x and y's of each persons hand, by putting a canvas down, then an image on top of it, then 4 ellipses, like:

, then scaling the position of them to peoples joints, (see Channel 9 for how to do this). Then I would copy the coordinates to a double to then set the pixels of them. Do that like this.
double person1hand1x = Canvas.GetLeft(person1hand1);
double person1hand1y =  Canvas.GetTop(person1hand1);

Then I would change the color of the canvas based on those actions by using the Image control. import the System.Drawing resource into your project, you will need it to set the pixels Then create a Bitmap and set the pixels of it as where the x and y's have been. Do that like this:

        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);
    }

Hope this helps! Note: I got the ToBitmapSource from Load a WPF BitmapImage from a System.Drawing.Bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!