|Kinect SDK 1 - Skeletons|
|Written by Mike James|
|Friday, 23 March 2012|
Page 2 of 4
Using the GDI
The key idea in the way that Windows Forms provides the facilities of the GDI is the Graphics object. This is a wrapper around the underlying operating system graphics used to draw everything you see on the screen.To make use of it you need to create a Graphics object which provides all of the methods you need to draw on that object. Clearly not all objects can be drawn on and not all objects can be associated with a Graphics object - but a Bitmap can.
So if you have converted the bit array into a Bitmap
using the function introduced in chapter 2, you can obtain a Graphic object to enable you to draw on the Bitmap.
For completeness here is the listing of the ImageToBitmap function - for an explaination refer to chapter 2:
Once you have a Bitmap of the video data then you can process it using the standard facilities provided by the API. In particular you can obtain a Graphics object:
Graphics g = Graphics.FromImage(bmap);
Now you can use the drawing methods provided by Graphics to draw on the Bitmap. So for example:
will draw an ellipse on the bitmap as specified by the Pen and the Rectangle which contains the ellipse.
Now that you have seen how this works you can look up the drawing methods of the Graphics object and use them to draw almost anything on the Bitmap. For eaxmple to draw a line you can use:
which draws a line in the specified Pen from x1,y1 to x2,y2 and
which draws a line from Point1 to Point2.
Notice that all of the co-ordinates are in pixels and so as long as we convert Kinect co-ordinates to pixel co-ordinates in the video Bitmap we can just use them to draw.
Displaying the Video
With this all of this explained we can convert the raw data into a bitmap and display it. Place a PictureBox on the form and add:
Bitmap bmap = ImageToBitmap(VFrame);
To the end of the FrameReady method. You also need to add:
The complete FrameReady method is:
void FramesReady(object sender,
If you run the program as it is you will see the video captured by the Kinect displayed in the PictureBox.
To make sure that the program ends without an error you also need to add the FormClosing event handler:
private void Form1_FormClosing(
|Last Updated ( Friday, 27 April 2012 )|