0

我正在编写一个程序,将一些Kinect数据呈现为小位图(记录的手势预览\帧预览)。我有一个类将映射的 Kinect 数据存储到屏幕 (X = [0; 1], Y = [0, 1]); 现在我想在小位图上绘制数据并显示在我的表单上。问题是“创建”位图......它是空的(透明的)。

这是我的映射数据类:

public class MappedJointData
{
    public JointType JointType { get; set; }
    public PointF MappedPosition { get; set; }
    public int Depth { get; set; }
    public JointTrackingState JointTrackingState { get; set; }
    public bool Seated { get; set; }
}

然后我写了一个扩展类,它应该从数据中返回位图:

public static Bitmap ToBitmap(this RecordedSkeletonFrame frame, int width, int height)
{
    return DrawBonesAndJoints(frame.MappedJointData, width, height);
}

private static Bitmap DrawBonesAndJoints(List<MappedJointData> mappedJointData, int width, int height)
{
    Bitmap b = new Bitmap(width, height);
    using (Graphics g = Graphics.FromImage(b))
    {
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.Clear(Color.Black);

        // (...)
        g.DrawEllipse(new Pen(drawBrush), joint.MappedPosition.X, joint.MappedPosition.Y, 3, 3);

        // (...)
        g.DrawLine(drawPen, joint0.MappedPosition.X, joint0.MappedPosition.Y, joint1.MappedPosition.X, joint1.MappedPosition.Y);
    }
    return b;
}

成功录制后,我想浏览映射数据并绘制位图:

foreach (RecordedSkeletonFrame frame in _gestureRecorder.Frames)
{
    FrameImages.Add(frame.ToBitmap(100, 75));
}

FrameImages是我ObservableCollection<Bitmap>绑定到的ListView(绑定应该可以工作,因为我使用一些已经渲染的图像对其进行了测试)。

为什么它不起作用?我试图在网络上找到一些东西,但是人们完全像我一样这样做。我不知道问题出在哪里。即使我渲染的数据很糟糕(但我不是设置了断点并检查了 and 的值XYg.Clear(Color.Black);应该让我的位图变黑吗?

4

1 回答 1

0

我确定您的问题不在粘贴的代码部分。不知何故,您会丢失/覆盖 FrameImages 或类似的数据。使用和图形部分肯定可以工作。

于 2013-01-16T23:21:31.720 回答