最初に、私が達成したいことをお見せしましょう。
http://www.youtube.com/watch?NR=1&feature=endscreen&v=FdwZEepJxJ4
そこで男はkinectを使って長い曲線を描いています。似たようなものを作る必要があります。次のような単純なコードだけでいくつかのアイデアがありました
layoutGrid.Children.Add(マイライン)
これは機能しますが、私が望む方法ではありません。
drawingContext を使用して線を描画できると考えていました:
drawingContext.DrawLine(drawPen, pointprev, point1);
問題は、この描画方法を使用すると、描画した線が画面に保持されないことです。線が常に引き直されているようなものです。ラインを維持するにはどうすればよいですか?
ところで、同じ方法で描画されたスケルトンが更新され、画像の前の行をクリアする必要がない理由もわかりませんか?
private void WindowLoaded(object sender, RoutedEventArgs e)
{
// Create the drawing group we'll use for drawing
this.drawingGroup = new DrawingGroup();
// Create an image source that we can use in our image control
this.imageSource = new DrawingImage(this.drawingGroup);
// Display the drawing using our image control
Image2.Source = this.imageSource;
************Some other code here*******
}
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
*****************Some code to get skeleton data here********
using (DrawingContext dc = this.drawingGroup.Open())
{
if (skeletons.Length != 0)
{
foreach (Skeleton skel in skeletons)
{
if (skel.TrackingState == SkeletonTrackingState.Tracked)
{
this.DrawBonesAndJoints(skel, dc);
}
}
}
}
}
private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
{
***********************Some code to draw skeleton***************
Joint righthand = skeleton.Joints[JointType.HandRight];
if (init == true)
{
pointprev = SkeletonPointToScreen(righthand.Position);
init = false;
return;
}
Point point1 = SkeletonPointToScreen(righthand.Position);
Pen drawPen = this.trackedBonePen;
drawingContext.DrawLine(drawPen, pointprev, point1);
pointprev = point1;
}
private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
{
// Convert point to depth space.
// We are not using depth directly, but we do want the points in our 640x480 output resolution.
DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);
return new Point(depthPoint.X, depthPoint.Y);
}
private void DrawBone(Skeleton skeleton, DrawingContext drawingContext, JointType jointType0, JointType jointType1)
{
Joint joint0 = skeleton.Joints[jointType0];
Joint joint1 = skeleton.Joints[jointType1];
Pen drawPen = this.trackedBonePen;
drawingContext.DrawLine(drawPen, this.SkeletonPointToScreen(joint0.Position), this.SkeletonPointToScreen(joint1.Position));
}