|
@@ -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;
|