首页新闻找找看学习计划

缓冲区大小不足 问题

0
悬赏园豆:100 [已关闭问题] 关闭于 2015-01-16 09:31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;

namespace Wpf
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            startKinect();
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            _kinect.Stop();
        }

        KinectSensor _kinect;
        private void startKinect()
        {
            if (KinectSensor.KinectSensors.Count>0)
            {
                _kinect = KinectSensor.KinectSensors[0];
                MessageBox.Show("Kinect 状态为:" + _kinect.Status);
                _kinect.ColorStream.Enable(ColorImageFormat.RawBayerResolution640x480Fps30);
                _kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                _kinect.SkeletonStream.Enable();

                _kinect.AllFramesReady +=new EventHandler<AllFramesReadyEventArgs>(_kinect_AllFramesReady);

                _kinect.Start();
            }
            else
            {
                MessageBox.Show("未发现Kinect设备");
            }
        }

        void _kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame=e.OpenColorImageFrame())
            {
                if (colorFrame == null)
                {
                    return;
                }
                byte[] pixels = new byte[colorFrame.PixelDataLength];
                colorFrame.CopyPixelDataTo(pixels);
                int strid = colorFrame.Width * 4;
                colorImage.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr24, null, pixels, strid);
            }
        }
    }
}

小严的主页 小严 | 初学一级 | 园豆:2
提问于:2015-01-14 16:57
< >
分享
所有回答(3)
0

这里不是缓存不足,而是你BitmapPalette不能为null

arg | 园豆:1047 (小虾三级) | 2015-01-14 20:07

谢谢你的 回答 错误已找到  但不是这个  

  _kinect.ColorStream.Enable(ColorImageFormat.RawBayerResolution640x480Fps30);

参数错误

支持(0) 反对(0) 小严 | 园豆:2 (初学一级) | 2015-01-16 09:30
0

猜测是变量pixels或者strid的内存空间有问题

jello chen | 园豆:7091 (大侠五级) | 2015-01-15 21:30

谢谢你的 回答 错误已找到  但不是这个  

_kinect.ColorStream.Enable(ColorImageFormat.RawBayerResolution640x480Fps30);

参数错误

支持(0) 反对(0) 小严 | 园豆:2 (初学一级) | 2015-01-16 09:30
0

 错误已找到 

_kinect.ColorStream.Enable(ColorImageFormat.RawBayerResolution640x480Fps30);

参数错误

小严 | 园豆:2 (初学一级) | 2015-01-16 09:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册