使用 Kinect 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);
}
我想从我的应用程序文件夹路径添加一个小的 jpeg 图像,而不是椭圆。
Image img = new Image
{
Width = 20,
Height = 20,
Source = new BitmapImage(new Uri("your/image/relative/path", UriKind.Relative)),
};
Canvas.SetLeft(img, joint.Position.X - img.Width / 2);
Canvas.SetTop(img, joint.Position.Y - img.Height / 2);
canvas.Children.Add(img);
您必须将 CacheOption 设置为 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);
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);
}
我想从我的应用程序文件夹路径添加一个小的 jpeg 图像,而不是椭圆。
Image img = new Image
{
Width = 20,
Height = 20,
Source = new BitmapImage(new Uri("your/image/relative/path", UriKind.Relative)),
};
Canvas.SetLeft(img, joint.Position.X - img.Width / 2);
Canvas.SetTop(img, joint.Position.Y - img.Height / 2);
canvas.Children.Add(img);
您必须将 CacheOption 设置为 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);