diff --git a/KinectConnection/BodyImageStream.cs b/KinectConnection/BodyImageStream.cs
index 4f5a271..99aa3ae 100644
--- a/KinectConnection/BodyImageStream.cs
+++ b/KinectConnection/BodyImageStream.cs
@@ -14,17 +14,6 @@ namespace KinectConnection
{
public class BodyImageStream : KinectStream
{
- ///
- /// The writeable bitmap.
- ///
- private WriteableBitmap bitmap = null;
-
- // so that we can bind to it in the MainWindow.xaml
- public WriteableBitmap Bitmap
- {
- get { return this.bitmap; }
- }
-
private BodyFrameReader bodyFrameReader = null;
private Body[] bodies = null;
private DrawingGroup drawingGroup = new DrawingGroup();
@@ -103,8 +92,6 @@ namespace KinectConnection
public override void Start()
{
- this.bitmap = new WriteableBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Pbgra32, null);
-
if (this.KinectSensor != null)
{
this.bodyFrameReader = this.KinectSensor.BodyFrameSource.OpenReader();
@@ -118,7 +105,15 @@ namespace KinectConnection
public override void Stop()
{
- throw new NotImplementedException();
+ if (this.bodyFrameReader != null)
+ {
+ this.bodyFrameReader.FrameArrived -= this.Reader_BodyFrameArrived;
+
+ // Dispose the reader to free resources.
+ // If we don't dispose manualy, the gc will do it for us, but we don't know when.
+ this.bodyFrameReader.Dispose();
+ this.bodyFrameReader = null;
+ }
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
diff --git a/KinectConnection/ColorImageStream.cs b/KinectConnection/ColorImageStream.cs
index bb43227..1f14a00 100644
--- a/KinectConnection/ColorImageStream.cs
+++ b/KinectConnection/ColorImageStream.cs
@@ -28,20 +28,24 @@ namespace KinectConnection
public ColorImageStream() : base()
{
+ // create the colorFrameDescription from the ColorFrameSource using rgba format
+ // the dimensions of the bitmap => match the dimensions of the color frame from the Kinect sensor.
+ FrameDescription colorFrameDescription = this.KinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
+ this.bitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
}
public override void Start()
{
- // create the colorFrameDescription from the ColorFrameSource using rgba format
- // the dimensions of the bitmap => match the dimensions of the color frame from the Kinect sensor.
- FrameDescription colorFrameDescription = this.KinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
- this.bitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
+ if (this.KinectSensor != null)
+ {
+ this.reader = this.KinectSensor.ColorFrameSource.OpenReader();
- // open the reader for the color frames
- this.reader = this.KinectSensor.ColorFrameSource.OpenReader();
- // subscribe to the event
- this.reader.FrameArrived += this.Reader_ColorFrameArrived;
+ if (this.reader != null)
+ {
+ this.reader.FrameArrived += this.Reader_ColorFrameArrived;
+ }
+ }
}
public override void Stop()
diff --git a/KinectConnection/DepthImageStream.cs b/KinectConnection/DepthImageStream.cs
index 0429cff..aab4c76 100644
--- a/KinectConnection/DepthImageStream.cs
+++ b/KinectConnection/DepthImageStream.cs
@@ -57,15 +57,6 @@ namespace KinectConnection
public override void Start()
{
- // get FrameDescription from DepthFrameSource
- this.depthFrameDescription = this.KinectSensor.DepthFrameSource.FrameDescription;
-
- // allocate space to put the pixels being received and converted
- this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];
-
- // create the bitmap to display
- this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
-
if (this.KinectSensor != null)
{
// open the reader for the depth frames
@@ -81,7 +72,27 @@ namespace KinectConnection
public override void Stop()
{
- throw new NotImplementedException();
+ if (this.depthFrameReader != null)
+ {
+ this.depthFrameReader.FrameArrived -= this.Reader_FrameArrived;
+
+ // Dispose the reader to free resources.
+ // If we don't dispose manualy, the gc will do it for us, but we don't know when.
+ this.depthFrameReader.Dispose();
+ this.depthFrameReader = null;
+ }
+ }
+
+ public DepthImageStream() : base()
+ {
+ // get FrameDescription from DepthFrameSource
+ this.depthFrameDescription = this.KinectSensor.DepthFrameSource.FrameDescription;
+
+ // allocate space to put the pixels being received and converted
+ this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];
+
+ // create the bitmap to display
+ this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
}
///
diff --git a/KinectConnection/InfraredImageStream.cs b/KinectConnection/InfraredImageStream.cs
index a4a17c8..e77d3bd 100644
--- a/KinectConnection/InfraredImageStream.cs
+++ b/KinectConnection/InfraredImageStream.cs
@@ -95,13 +95,13 @@ namespace KinectConnection
{
// get FrameDescription from InfraredFrameSource
this.infraredFrameDescription = this.KinectSensor.InfraredFrameSource.FrameDescription;
- }
- public override void Start()
- {
// create the bitmap to display
this.infraredBitmap = new WriteableBitmap(this.infraredFrameDescription.Width, this.infraredFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray32Float, null);
+ }
+ public override void Start()
+ {
if (this.KinectSensor != null)
{
// open the reader for the depth frames
@@ -117,7 +117,15 @@ namespace KinectConnection
public override void Stop()
{
- throw new NotImplementedException();
+ if (this.infraredFrameReader != null)
+ {
+ this.infraredFrameReader.FrameArrived -= this.Reader_InfraredFrameArrived;
+
+ // Dispose the reader to free resources.
+ // If we don't dispose manualy, the gc will do it for us, but we don't know when.
+ this.infraredFrameReader.Dispose();
+ this.infraredFrameReader = null;
+ }
}
///
diff --git a/KinectSensorStreams/View/MainWindow.xaml b/KinectSensorStreams/View/MainWindow.xaml
index 3c6122d..e91a951 100644
--- a/KinectSensorStreams/View/MainWindow.xaml
+++ b/KinectSensorStreams/View/MainWindow.xaml
@@ -70,7 +70,8 @@