Search code examples
c#wpfkinectkinect-sdk

Add an image instead of an Ellipse when draw skeleton using Kinect SDK


public static void DrawSkeleton(this Canvas canvas, Body body)
{
    foreach (Joint joint in body.Joints.Values)
    {
        canvas.DrawPoint(joint);
    }
}

public static void DrawPoint(this Canvas canvas, Joint joint)
{
    joint = joint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight);

    Ellipse ellipse = new Ellipse
    {
         Width = 20,
         Height = 20,
         Fill = new SolidColorBrush(Colors.LightBlue)
    };

    Canvas.SetLeft(ellipse, joint.Position.X - ellipse.Width / 2);
    Canvas.SetTop(ellipse, joint.Position.Y - ellipse.Height / 2);

    canvas.Children.Add(ellipse);
}

I would like to add a small jpeg image from my application folder path, instead of an ellipse.


Solution

  • You have to set the CacheOption to OnLoad:

            var bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = new Uri("yourimage.png", UriKind.Relative);
            bitmap.CacheOption = BitmapCacheOption.OnLoad;
            bitmap.EndInit();
            var img = new Image{Source=bitmap};
    
            canvas.Children.Add(img);