diff -r 925b7ee746e3 -r a1bf0d21022e middleware/src/Debug/DebugWindow.xaml.cs --- a/middleware/src/Debug/DebugWindow.xaml.cs Fri Mar 23 16:24:36 2012 +0100 +++ b/middleware/src/Debug/DebugWindow.xaml.cs Mon Mar 26 16:22:51 2012 +0200 @@ -44,6 +44,8 @@ using Trakers.Tracking.Gestures; using System.Resources; using System.Reflection; +using System.Timers; +using Trakers.Communication; namespace Trakers.Debug { @@ -51,6 +53,8 @@ { //Gestionnaire de ressources. private ResourceManager rm; + //Timer. + private System.Timers.Timer _timer; //Membre permettant d'atteindre la classe KinectMain du sous-module Tracking. private KinectMain kinectMain; //Tableau contenant une image en couleurs. @@ -59,6 +63,8 @@ private bool on; //Indique si la fenêtre de debug est actuellement en cours de fermeture. private bool closing; + //Indique si l'image doit être raffraichie. + private Boolean refreshImage; /* * Constructeur : Affiche la fenêtre de debug en lui passant en paramètre une instanciation de la @@ -72,6 +78,27 @@ kinectMain = main; on = true; closing = false; + refreshImage = true; + + try + { + //On instancie le timer à N ms. + _timer = new System.Timers.Timer(kinectMain.getTimerElapsing()); + //Dès que le timer est expiré, on appelle _timer_Elapsed. + _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed); + } + catch (Exception){} + } + + /* + * Méthode appelée à l'expiration du timer pour les gestures et modes. + */ + public void _timer_Elapsed(object sender, ElapsedEventArgs e) + { + //On débloque le raffraichissement de l'image. + refreshImage = true; + //On arrête le timer. + _timer.Stop(); } /* @@ -134,54 +161,44 @@ */ public void RefreshVideo(AllFramesReadyEventArgs e) { - bool receivedData = false; - ColorImageFrame colorImageFrameData; - using (colorImageFrameData = e.OpenColorImageFrame()) + if (refreshImage) { - //Si on ne reçoit pas de trames de la kinect. - if (colorImageFrameData == null) + bool receivedData = false; + ColorImageFrame colorImageFrameData; + using (colorImageFrameData = e.OpenColorImageFrame()) { - //L'image est supprimée. - DebugImage.Source = null; - } - //Si le tableau stockant l'image en cours est nul. - if (colorPixelData == null) - //On alloue un nouveau tableau. - colorPixelData = new byte[colorImageFrameData.PixelDataLength]; - else - { - try + //Si on ne reçoit pas de trames de la kinect. + if (colorImageFrameData == null) { - //Sinon on met à jour le tableau en copiant le contenu de la trame dans le tableau. - colorImageFrameData.CopyPixelDataTo(colorPixelData); - receivedData = true; + //L'image est supprimée. + DebugImage.Source = null; } - catch (Exception){} + //Si le tableau stockant l'image en cours est nul. + if (colorPixelData == null) + //On alloue un nouveau tableau. + colorPixelData = new byte[colorImageFrameData.PixelDataLength]; + else + { + try + { + //Sinon on met à jour le tableau en copiant le contenu de la trame dans le tableau. + colorImageFrameData.CopyPixelDataTo(colorPixelData); + receivedData = true; + } + catch (Exception) { } + } } - } - //Si on a des données dans le tableau et que la kinect est allumée. - if (receivedData && on) - { - //Exemples de modifications de l'affichage : - //Zombies apocalypse. - //Black & White movie. - /*for (int i = 0; i < colorPixelData.Length; i += colorImageFrameData.BytesPerPixel) + //Si on a des données dans le tableau et que la kinect est allumée. + if (receivedData && on) { - byte gray = Math.Min(colorPixelData[i], colorPixelData[i + 1]); - gray = Math.Min(gray, colorPixelData[i + 2]); - colorPixelData[i] = gray; - colorPixelData[i + 1] = gray; - - colorPixelData[i] = colorPixelData[i + 1]; - colorPixelData[i + 1] = colorPixelData[i]; - colorPixelData[i + 2] = (byte)~colorPixelData[i + 2]; - }*/ - - //On met à jour l'image de la caméra. - DebugImage.Source = BitmapSource.Create(colorImageFrameData.Width, colorImageFrameData.Height, 96, 96, PixelFormats.Bgr32, null, colorPixelData, colorImageFrameData.Width * colorImageFrameData.BytesPerPixel); - DebugImage.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; - DebugImage.VerticalAlignment = System.Windows.VerticalAlignment.Center; - DebugImage.Stretch = Stretch.Fill; + //On met à jour l'image de la caméra. + DebugImage.Source = BitmapSource.Create(colorImageFrameData.Width, colorImageFrameData.Height, 96, 96, PixelFormats.Bgr32, null, colorPixelData, colorImageFrameData.Width * colorImageFrameData.BytesPerPixel); + DebugImage.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; + DebugImage.VerticalAlignment = System.Windows.VerticalAlignment.Center; + DebugImage.Stretch = Stretch.Fill; + //On annule l'image associée aux gestures. + Gestures.Source = null; + } } } @@ -189,43 +206,178 @@ * Affiche la distance de l'utilisateur dans le rendu visuel. * Sous forme de nombre en m et de rectangles changeant de couleur en fonction de la distance. */ - public void showDistance(float distance) + public void showDistance(float proximity) { - DistanceLbl.Content = "Distance : " + distance; + DistanceLbl.Content = "Proximity : " + proximity + "%"; - if (distance > 0 && distance < 1) + if (proximity == 0) + { + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; + R2.Fill = System.Windows.Media.Brushes.DarkGray; + R3.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.DarkGray; + R6.Fill = System.Windows.Media.Brushes.DarkGray; + R7.Fill = System.Windows.Media.Brushes.DarkGray; + R8.Fill = System.Windows.Media.Brushes.DarkGray; + R9.Fill = System.Windows.Media.Brushes.DarkGray; + R10.Fill = System.Windows.Media.Brushes.DarkGray; + } + else if (proximity > 0 && proximity < 10) + { + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; + R2.Fill = System.Windows.Media.Brushes.DarkGray; + R3.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.DarkGray; + R6.Fill = System.Windows.Media.Brushes.DarkGray; + R7.Fill = System.Windows.Media.Brushes.DarkGray; + R8.Fill = System.Windows.Media.Brushes.DarkGray; + R9.Fill = System.Windows.Media.Brushes.DarkGray; + R10.Fill = System.Windows.Media.Brushes.Red; + } + else if (proximity > 10 && proximity < 20) { - R1.Fill = System.Windows.Media.Brushes.Red; + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; + R2.Fill = System.Windows.Media.Brushes.DarkGray; + R3.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.DarkGray; + R6.Fill = System.Windows.Media.Brushes.DarkGray; + R7.Fill = System.Windows.Media.Brushes.DarkGray; + R8.Fill = System.Windows.Media.Brushes.DarkGray; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; + } + else if (proximity > 20 && proximity < 30) + { + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; + R2.Fill = System.Windows.Media.Brushes.DarkGray; + R3.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.DarkGray; + R6.Fill = System.Windows.Media.Brushes.DarkGray; + R7.Fill = System.Windows.Media.Brushes.DarkGray; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; + } + else if (proximity > 30 && proximity < 40) + { + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; + R2.Fill = System.Windows.Media.Brushes.DarkGray; + R3.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.DarkGray; + R6.Fill = System.Windows.Media.Brushes.DarkGray; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; + } + else if (proximity > 40 && proximity < 50) + { + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; R2.Fill = System.Windows.Media.Brushes.DarkGray; R3.Fill = System.Windows.Media.Brushes.DarkGray; R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.DarkGray; + R6.Fill = System.Windows.Media.Brushes.Orange; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; } - else if (distance > 1 && distance < 2) + else if (proximity > 50 && proximity < 60) { + R0.Fill = System.Windows.Media.Brushes.DarkGray; R1.Fill = System.Windows.Media.Brushes.DarkGray; - R2.Fill = System.Windows.Media.Brushes.Orange; + R2.Fill = System.Windows.Media.Brushes.DarkGray; R3.Fill = System.Windows.Media.Brushes.DarkGray; R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.Orange; + R6.Fill = System.Windows.Media.Brushes.Orange; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; } - else if (distance > 2 && distance < 3) + else if (proximity > 60 && proximity < 70) { + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; + R2.Fill = System.Windows.Media.Brushes.DarkGray; + R3.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.Yellow; + R5.Fill = System.Windows.Media.Brushes.Orange; + R6.Fill = System.Windows.Media.Brushes.Orange; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; + } + else if (proximity > 70 && proximity < 80) + { + R0.Fill = System.Windows.Media.Brushes.DarkGray; R1.Fill = System.Windows.Media.Brushes.DarkGray; R2.Fill = System.Windows.Media.Brushes.DarkGray; R3.Fill = System.Windows.Media.Brushes.Yellow; - R4.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.Yellow; + R5.Fill = System.Windows.Media.Brushes.Orange; + R6.Fill = System.Windows.Media.Brushes.Orange; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; } - else if (distance > 3 && distance < 4) + else if (proximity > 80 && proximity < 90) { + R0.Fill = System.Windows.Media.Brushes.DarkGray; R1.Fill = System.Windows.Media.Brushes.DarkGray; - R2.Fill = System.Windows.Media.Brushes.DarkGray; - R3.Fill = System.Windows.Media.Brushes.DarkGray; - R4.Fill = System.Windows.Media.Brushes.White; + R2.Fill = System.Windows.Media.Brushes.Yellow; + R3.Fill = System.Windows.Media.Brushes.Yellow; + R4.Fill = System.Windows.Media.Brushes.Yellow; + R5.Fill = System.Windows.Media.Brushes.Orange; + R6.Fill = System.Windows.Media.Brushes.Orange; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; } - } - - public void showProximity(UserPositionEventArgs e) - { - + else if (proximity > 90 && proximity < 100) + { + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.Yellow; + R2.Fill = System.Windows.Media.Brushes.Yellow; + R3.Fill = System.Windows.Media.Brushes.Yellow; + R4.Fill = System.Windows.Media.Brushes.Yellow; + R5.Fill = System.Windows.Media.Brushes.Orange; + R6.Fill = System.Windows.Media.Brushes.Orange; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; + } + else if (proximity == 100) + { + R0.Fill = System.Windows.Media.Brushes.Green; + R1.Fill = System.Windows.Media.Brushes.Yellow; + R2.Fill = System.Windows.Media.Brushes.Yellow; + R3.Fill = System.Windows.Media.Brushes.Yellow; + R4.Fill = System.Windows.Media.Brushes.Yellow; + R5.Fill = System.Windows.Media.Brushes.Orange; + R6.Fill = System.Windows.Media.Brushes.Orange; + R7.Fill = System.Windows.Media.Brushes.Orange; + R8.Fill = System.Windows.Media.Brushes.Red; + R9.Fill = System.Windows.Media.Brushes.Red; + R10.Fill = System.Windows.Media.Brushes.Red; + } } /* @@ -255,36 +407,39 @@ */ public void drawJoints(JointCollection joints, Skeleton first) { - //On enlève tout élément du Canvas à part l'image, de manière à mettre à jour la position du squelette. - DebugCanvas.Children.RemoveRange(1, DebugCanvas.Children.Count - 1); + if (refreshImage) + { + //On enlève tout élément du Canvas à part l'image, de manière à mettre à jour la position du squelette. + DebugCanvas.Children.RemoveRange(1, DebugCanvas.Children.Count - 1); - //Pour chaque noeud. - foreach (Joint joint in first.Joints) - { - //On crée une ellipse de taille 20 et de largeur 20. - Ellipse node = new Ellipse(); - node.Height = 20; - node.Width = 20; + //Pour chaque noeud. + foreach (Joint joint in first.Joints) + { + //On crée une ellipse de taille 20 et de largeur 20. + Ellipse node = new Ellipse(); + node.Height = 20; + node.Width = 20; - //S'il s'agit d'un noeud de tête, on le colorie en rouge, sinon en bleu. - if (joint.JointType == JointType.Head) - node.Fill = System.Windows.Media.Brushes.Red; - else if(joint.JointType == JointType.ShoulderCenter) - node.Fill = System.Windows.Media.Brushes.Green; - else if(joint.JointType == JointType.HipCenter) - node.Fill = System.Windows.Media.Brushes.Green; - else if (joint.JointType == JointType.HandRight) - node.Fill = System.Windows.Media.Brushes.Red; - else - node.Fill = System.Windows.Media.Brushes.Blue; + //S'il s'agit d'un noeud de tête, on le colorie en rouge, sinon en bleu. + if (joint.JointType == JointType.Head) + node.Fill = System.Windows.Media.Brushes.Red; + else if (joint.JointType == JointType.ShoulderCenter) + node.Fill = System.Windows.Media.Brushes.Green; + else if (joint.JointType == JointType.HipCenter) + node.Fill = System.Windows.Media.Brushes.Green; + else if (joint.JointType == JointType.HandRight) + node.Fill = System.Windows.Media.Brushes.Red; + else + node.Fill = System.Windows.Media.Brushes.Blue; - //On met à la bonne échelle les coordonnées des positions des noeuds. - Joint scaledJoint = Coding4Fun.Kinect.Wpf.SkeletalExtensions.ScaleTo(joint, 600, 400, 0.75f, 0.75f); + //On met à la bonne échelle les coordonnées des positions des noeuds. + Joint scaledJoint = Coding4Fun.Kinect.Wpf.SkeletalExtensions.ScaleTo(joint, 600, 400, 0.75f, 0.75f); - //On positionne le noeud dans le Canvas, et on l'ajoute. - Canvas.SetLeft(node, scaledJoint.Position.X); - Canvas.SetTop(node, scaledJoint.Position.Y); - DebugCanvas.Children.Add(node); + //On positionne le noeud dans le Canvas, et on l'ajoute. + Canvas.SetLeft(node, scaledJoint.Position.X); + Canvas.SetTop(node, scaledJoint.Position.Y); + DebugCanvas.Children.Add(node); + } } } @@ -302,7 +457,6 @@ line.Y2 = j2.Position.Y; line.StrokeThickness = 8; DebugCanvas.Children.Add(line); - ExceptionLbl.Content = DebugCanvas.Children.Count; } /* @@ -310,32 +464,53 @@ */ public void showSkeleton(Joint hipCenter, Joint spine, Joint shoulderCenter, Joint head, Joint shoulderLeft, Joint elbowLeft, Joint wristLeft, Joint handLeft, Joint shoulderRight, Joint elbowRight, Joint wristRight, Joint handRight, Joint hipLeft, Joint kneeLeft, Joint ankleLeft, Joint footLeft, Joint hipRight, Joint kneeRight, Joint ankleRight, Joint footRight) { - //On met les noeuds deux par deux en fonction de leur position dans le squelette. - drawBone(head, shoulderCenter); - drawBone(shoulderCenter, shoulderLeft); - drawBone(shoulderLeft, elbowLeft); - drawBone(elbowLeft, wristLeft); - drawBone(wristLeft, handLeft); - drawBone(shoulderCenter, shoulderRight); - drawBone(shoulderRight, elbowRight); - drawBone(elbowRight, wristRight); - drawBone(wristRight, handRight); - drawBone(shoulderCenter, spine); - drawBone(spine, hipCenter); - drawBone(hipCenter, hipLeft); - drawBone(hipLeft, kneeLeft); - drawBone(kneeLeft, ankleLeft); - drawBone(ankleLeft, footLeft); - drawBone(hipCenter, hipRight); - drawBone(hipRight, kneeRight); - drawBone(kneeRight, ankleRight); - drawBone(ankleRight, footRight); + if (refreshImage) + { + //On met les noeuds deux par deux en fonction de leur position dans le squelette. + drawBone(head, shoulderCenter); + drawBone(shoulderCenter, shoulderLeft); + drawBone(shoulderLeft, elbowLeft); + drawBone(elbowLeft, wristLeft); + drawBone(wristLeft, handLeft); + drawBone(shoulderCenter, shoulderRight); + drawBone(shoulderRight, elbowRight); + drawBone(elbowRight, wristRight); + drawBone(wristRight, handRight); + drawBone(shoulderCenter, spine); + drawBone(spine, hipCenter); + drawBone(hipCenter, hipLeft); + drawBone(hipLeft, kneeLeft); + drawBone(kneeLeft, ankleLeft); + drawBone(ankleLeft, footLeft); + drawBone(hipCenter, hipRight); + drawBone(hipRight, kneeRight); + drawBone(kneeRight, ankleRight); + drawBone(ankleRight, footRight); + } } + /* + * Cache le squelette et le reste de l'interface à part l'image. + */ public void hideSkeleton() { + //On vide le canvas mais en gardant l'image. if(DebugCanvas.Children.Count > 1) DebugCanvas.Children.RemoveRange(1, DebugCanvas.Children.Count - 1); + //On colore en gris tous les indicateurs. + R0.Fill = System.Windows.Media.Brushes.DarkGray; + R1.Fill = System.Windows.Media.Brushes.DarkGray; + R2.Fill = System.Windows.Media.Brushes.DarkGray; + R3.Fill = System.Windows.Media.Brushes.DarkGray; + R4.Fill = System.Windows.Media.Brushes.DarkGray; + R5.Fill = System.Windows.Media.Brushes.DarkGray; + R6.Fill = System.Windows.Media.Brushes.DarkGray; + R7.Fill = System.Windows.Media.Brushes.DarkGray; + R8.Fill = System.Windows.Media.Brushes.DarkGray; + R9.Fill = System.Windows.Media.Brushes.DarkGray; + R10.Fill = System.Windows.Media.Brushes.DarkGray; + LeftHand.Background = System.Windows.Media.Brushes.DarkGray; + RightHand.Background = System.Windows.Media.Brushes.DarkGray; } /* @@ -354,42 +529,6 @@ RightHand.Content = coord; } - public void showSwipe(SwipeEventArgs e) - { - if(e.direction == Tracking.Gestures.SwipeDetector.Direction.LEFT) - ExceptionLbl.Background = System.Windows.Media.Brushes.Red; - else if(e.direction == Tracking.Gestures.SwipeDetector.Direction.RIGHT) - ExceptionLbl.Background = System.Windows.Media.Brushes.Purple; - } - - public void showPush(PushEventArgs e) - { - if (e.direction == Tracking.Gestures.PushDetector.Direction.PUSH) - { - if(e.hand == Tracking.Gestures.PushDetector.Hand.LEFT) - LeftHand.Background = System.Windows.Media.Brushes.White; - else if(e.hand == Tracking.Gestures.PushDetector.Hand.RIGHT) - RightHand.Background = System.Windows.Media.Brushes.White; - else - { - LeftHand.Background = System.Windows.Media.Brushes.White; - RightHand.Background = System.Windows.Media.Brushes.White; - } - } - else - { - if (e.hand == Tracking.Gestures.PushDetector.Hand.LEFT) - LeftHand.Background = System.Windows.Media.Brushes.Black; - else if (e.hand == Tracking.Gestures.PushDetector.Hand.RIGHT) - RightHand.Background = System.Windows.Media.Brushes.Black; - else - { - LeftHand.Background = System.Windows.Media.Brushes.Black; - RightHand.Background = System.Windows.Media.Brushes.Black; - } - } - } - /* * Méthode associée à l'événement : Ouvrir la fenêtre de paramétrage via le menu. */ @@ -418,9 +557,73 @@ Application.Current.Shutdown(); } + /* + * Permet d'initialiser la Kinect dès que la fenêtre est lancée. + */ private void Window_Loaded(object sender, RoutedEventArgs e) { kinectMain.KinectInitialization(); } + + /* + * Méthode d'affichage des gestures. + */ + public void showGesture(String gesture) + { + if (refreshImage) + { + refreshImage = false; + _timer.Start(); + Bitmap bitmap = null; + //S'il s'agit de telle ou telle gesture, on prend l'image correspondante dans les ressources, + //on la convertit et on l'affiche. + switch (gesture) + { + case "SWIPE-LEFT": bitmap = (Bitmap)rm.GetObject("swipe_left"); + break; + case "SWIPE-RIGHT": bitmap = (Bitmap)rm.GetObject("swipe_right"); + break; + case "PUSH-RIGHT": bitmap = (Bitmap)rm.GetObject("push_right"); + break; + case "PUSH-LEFT": bitmap = (Bitmap)rm.GetObject("push_left"); + break; + case "PUSH-BOTH": bitmap = (Bitmap)rm.GetObject("push_both"); + break; + case "PULL-RIGHT": bitmap = (Bitmap)rm.GetObject("pull_right"); + break; + case "PULL-LEFT": bitmap = (Bitmap)rm.GetObject("pull_left"); + break; + case "PULL-BOTH": bitmap = (Bitmap)rm.GetObject("pull_both"); + break; + } + Gestures.Source = CreateBitmapSourceFromBitmap(bitmap); + } + + DebugImage.Source = null; + hideSkeleton(); + } + + /* + * Méthode d'indication de raffraichissement de l'image ("on la raffraichit ou pas ?"). + */ + public void setRefreshImage(bool refresh) + { + refreshImage = refresh; + } + + /* + * Méthode de conversion de Bitmap (des ressources) en BitmapSource (du debug). + */ + public static BitmapSource CreateBitmapSourceFromBitmap(Bitmap bitmap) + { + if (bitmap == null) + return null; + + return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( + bitmap.GetHbitmap(), + IntPtr.Zero, + Int32Rect.Empty, + BitmapSizeOptions.FromEmptyOptions()); + } } }