Browse Source

完善彩色画面显示

Yumin 6 years ago
parent
commit
e91e89dc66

BIN
.vs/KinectCar/v14/.suo


+ 2 - 3
KinectCar/MainWindow.xaml

@@ -4,18 +4,17 @@
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
-        Title="MainWindow" Height="400" Width="400" KeyDown="Window_KeyDown" ResizeMode="CanMinimize" Loaded="Window_Loaded" Closing="Window_Closing">
+        Title="体感控制器" Height="400" Width="600" KeyDown="Window_KeyDown" ResizeMode="CanMinimize" Loaded="Window_Loaded" Closing="Window_Closing">
     <Grid>
         <ToolBar x:Name="ToolBar" VerticalAlignment="Top" Padding="0,0" Margin="0,0" Height="32">
             <Button x:Name="Settings" Content="&#xF013; 设置" ToolTip="设置" Style="{StaticResource FontAwesome}" Click="Settings_Click" VerticalAlignment="Stretch"/>
             <Separator/>
             <Button x:Name="FullScreen" Content="&#xF31E; 全屏" ToolTip="全屏" Style="{StaticResource FontAwesome}" Click="FullScreen_Click" VerticalAlignment="Stretch"/>
             <Separator/>
-            <Label x:Name="Status" Content="准备" ToolTip="状态" Foreground="Gray"/>
+            <Label x:Name="Status" Content="{Binding StatusText}" ToolTip="状态" Foreground="Gray"/>
             <Separator/>
             <Label x:Name="FileName" Content="" Foreground="Gray"/>
         </ToolBar>
-        <Label Content="{Binding StatusText}" HorizontalAlignment="Left" Margin="10,67,0,0" VerticalAlignment="Top"/>
 
         <Viewbox x:Name="ViewBox" Margin="0,32,0,0" HorizontalAlignment="Center">
             <Image Name="Image" Source="{Binding ImageSource}" Stretch="UniformToFill" />

+ 27 - 20
KinectCar/MainWindow.xaml.cs

@@ -80,6 +80,25 @@ namespace KinectCar
             _bodyFrameReader = _kinectSensor.BodyFrameSource.OpenReader();
             // 打开颜色框架的渲染器
             _colorFrameReader = _kinectSensor.ColorFrameSource.OpenReader();
+            // 设置数据回调
+            if (_bodyFrameReader != null)
+            {
+                _bodyFrameReader.FrameArrived += Reader_FrameArrived;
+            }
+            if (_colorFrameReader != null)
+            {
+                _colorFrameReader.FrameArrived += Reader_ColorFrameArrived;
+            }
+            // 利用 BGRA 格式创建颜色描述来自颜色来源
+            var colorFrameDescription = _kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
+            // 创建要显示的位图
+            _colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
+
+            // 设置 IsAvailableChanged 事件通知程序
+            _kinectSensor.IsAvailableChanged += Sensor_IsAvailableChanged;
+            // 打开传感器
+            _kinectSensor.Open();
+
             // 骨骼定义为两个关节之间的线
             _bones = new List<Tuple<JointType, JointType>>
             {
@@ -114,10 +133,6 @@ namespace KinectCar
                 new Tuple<JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)
             };
             
-            // 设置 IsAvailableChanged 事件通知程序
-            _kinectSensor.IsAvailableChanged += Sensor_IsAvailableChanged;
-            // 打开传感器
-            _kinectSensor.Open();
             // 设置状态文本
             StatusText = _kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText;
             // 在这个简单的例子中使用window对象作为视图模型
@@ -128,19 +143,6 @@ namespace KinectCar
 
         private void Window_Loaded(object sender, RoutedEventArgs e)
         {
-            if (_bodyFrameReader != null)
-            {
-                _bodyFrameReader.FrameArrived += Reader_FrameArrived;
-            }
-            if (_colorFrameReader != null)
-            {
-                _colorFrameReader.FrameArrived += Reader_ColorFrameArrived;
-            }
-            // create the colorFrameDescription from the ColorFrameSource using Bgra format
-            var colorFrameDescription = _kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
-            // create the bitmap to display
-            _colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
-
             // 注册消息接收处理事件,还可以注册消息订阅成功、取消订阅成功、与服务器断开等事件处理函数
             _client.MqttMsgPublishReceived += ClientMqttMsgPublishReceived;
             //生成客户端 ID 并连接服务器
@@ -363,6 +365,11 @@ namespace KinectCar
                     WindowState = WindowState.Normal;
                     WindowStyle = WindowStyle.SingleBorderWindow;
                     break;
+                case Key.Space:
+                    //var bitmapImage = new BitmapImage(new Uri("I:\\图片\\background.jpg", UriKind.Absolute));
+                    //_colorBitmap = new WriteableBitmap(bitmapImage);
+                    //StatusText = DateTime.Now.ToLongTimeString();
+                    break;
             }
         }
 
@@ -375,9 +382,9 @@ namespace KinectCar
         {
             ToolBar.Visibility = Visibility.Hidden;
             ViewBox.Margin = new Thickness { Left = 0, Top = 0, Right = 0, Bottom = 0 };
-            this.Topmost = false;
-            this.WindowStyle = WindowStyle.None;
-            this.WindowState = WindowState.Maximized;
+            Topmost = false;
+            WindowStyle = WindowStyle.None;
+            WindowState = WindowState.Maximized;
         }
 
         public ImageSource ImageSource => _colorBitmap;

+ 3 - 3
KinectCar/Properties/Resources.Designer.cs

@@ -61,7 +61,7 @@ namespace KinectCar.Properties {
         }
         
         /// <summary>
-        ///   查找类似 No ready Kinect found! 的本地化字符串。
+        ///   查找类似 未连接 Kinect! 的本地化字符串。
         /// </summary>
         internal static string NoSensorStatusText {
             get {
@@ -70,7 +70,7 @@ namespace KinectCar.Properties {
         }
         
         /// <summary>
-        ///   查找类似 Running 的本地化字符串。
+        ///   查找类似 运行中 的本地化字符串。
         /// </summary>
         internal static string RunningStatusText {
             get {
@@ -79,7 +79,7 @@ namespace KinectCar.Properties {
         }
         
         /// <summary>
-        ///   查找类似 Kinect not available! 的本地化字符串。
+        ///   查找类似 Kinect 不可用! 的本地化字符串。
         /// </summary>
         internal static string SensorNotAvailableStatusText {
             get {

+ 3 - 3
KinectCar/Properties/Resources.resx

@@ -118,12 +118,12 @@
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   <data name="NoSensorStatusText" xml:space="preserve">
-    <value>No ready Kinect found!</value>
+    <value>未连接 Kinect!</value>
   </data>
   <data name="RunningStatusText" xml:space="preserve">
-    <value>Running</value>
+    <value>运行中</value>
   </data>
   <data name="SensorNotAvailableStatusText" xml:space="preserve">
-    <value>Kinect not available!</value>
+    <value>Kinect 不可用!</value>
   </data>
 </root>