diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml
index ddc2611..4d481aa 100644
--- a/Sources/WpfApp/MainWindow.xaml
+++ b/Sources/WpfApp/MainWindow.xaml
@@ -26,6 +26,6 @@
-
+
\ No newline at end of file
diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs
index ddff775..a7b8165 100644
--- a/Sources/WpfApp/MainWindow.xaml.cs
+++ b/Sources/WpfApp/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Kinect;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -20,9 +21,76 @@ namespace WpfApp
///
public partial class MainWindow : Window
{
+ private KinectSensor kinectSensor = null;
+ private ColorFrameReader colorFrameReader = null;
+ private WriteableBitmap colorBitmap = null;
+
public MainWindow()
{
InitializeComponent();
+
+ // Initialiser la Kinect
+ this.kinectSensor = KinectSensor.GetDefault();
+
+ // Ouvrir le lecteur de flux de couleur
+ this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
+
+ // Frame description pour les images de couleur
+ FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
+
+ // Créer le bitmap pour afficher l'image
+ this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
+
+ // Gérer l'événement FrameArrived pour le flux de couleur
+ this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
+
+ // Ouvrir la Kinect
+ this.kinectSensor.Open();
+ }
+
+ private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
+ {
+ using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
+ {
+ if (colorFrame != null)
+ {
+ FrameDescription colorFrameDescription = colorFrame.FrameDescription;
+
+ using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
+ {
+ this.colorBitmap.Lock();
+
+ // Vérifier si la taille de l'image a changé
+ if ((colorFrameDescription.Width == this.colorBitmap.PixelWidth) && (colorFrameDescription.Height == this.colorBitmap.PixelHeight))
+ {
+ colorFrame.CopyConvertedFrameDataToIntPtr(
+ this.colorBitmap.BackBuffer,
+ (uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
+ ColorImageFormat.Bgra);
+
+ this.colorBitmap.AddDirtyRect(new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight));
+ }
+
+ this.colorBitmap.Unlock();
+ }
+ }
+ }
+ }
+
+ // Assurez-vous de fermer correctement le lecteur et le capteur Kinect lors de la fermeture de la fenêtre
+ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ if (this.colorFrameReader != null)
+ {
+ this.colorFrameReader.Dispose();
+ this.colorFrameReader = null;
+ }
+
+ if (this.kinectSensor != null)
+ {
+ this.kinectSensor.Close();
+ this.kinectSensor = null;
+ }
}
}
}
diff --git a/Sources/WpfApp/WpfApp.csproj b/Sources/WpfApp/WpfApp.csproj
index 3beb44b..950c7f9 100644
--- a/Sources/WpfApp/WpfApp.csproj
+++ b/Sources/WpfApp/WpfApp.csproj
@@ -35,6 +35,9 @@
4
+
+ ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll
+
@@ -86,6 +89,7 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/Sources/WpfApp/packages.config b/Sources/WpfApp/packages.config
new file mode 100644
index 0000000..f7f19c3
--- /dev/null
+++ b/Sources/WpfApp/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file