简体   繁体   English

图形无法在位图上绘制

[英]Graphics doesn't draw on Bitmap

I'm writing a program that renders some Kinect data into small bitmaps (recorded gesture preview\\frames preview). 我正在编写一个程序,将一些Kinect数据渲染为小的位图(记录的手势预览\\帧预览)。 I have a class that stores mapped Kinect data to screen (X = [0; 1], Y = [0, 1]); 我有一个将映射的Kinect数据存储到屏幕的类(X = [0; 1],Y = [0,1]); Now I want to draw the data on small bitmaps and display on my form. 现在,我想在小的位图上绘制数据并显示在表单上。 The problem is "created" bitmap... It's empty (transparent). 问题是“创建”位图...它是空的(透明的)。

It's my mapped data class: 这是我的映射数据类:

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

Then I wrote an extention class that should return bitmap from the data: 然后,我编写了一个扩展类,该类应该从数据中返回位图:

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

After successful recording I want to go through the mapped data and draw bitmaps: 成功记录后,我想浏览映射的数据并绘制位图:

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

FrameImages is my ObservableCollection<Bitmap> that is bound to the ListView (binding should work, because I tested it using some already rendered images). FrameImages是我的ObservableCollection<Bitmap> ,绑定到ListView (绑定应该起作用,因为我已经使用一些已经渲染的图像对其进行了测试)。

Why isn't it working? 为什么不起作用? I tried to find something in the web, but ppl do this exactly like me. 我试图在网上找到一些东西,但是ppl完全像我一样做。 I don't know where's the problem. 我不知道问题出在哪里。 Even if my rendered data is bad (but isn't I set a breakpoint up and checked values of X and Y ), g.Clear(Color.Black); 即使我的渲染数据很差(但不是设置断点并检查XY值), g.Clear(Color.Black); should make my bitmap black? 应该让我的位图变黑?

I'm sure your problem is not in the pasted code part. 我确定您的问题不在粘贴的代码部分中。 Somehow you lose/overwrite the data in FrameImages or something like that. 您以某种方式丢失/覆盖FrameImages中的数据或类似的东西。 The using and graphics part should definitely work. 使用和图形部分一定可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM