Kinect虚拟试衣间开发(3)-拍照和声控功能

  • 拍照

编写成一个函数,方便后面调用

 private void takephoto()
        {
            if (this.bitmap != null)
            {
                // Create a render target to which we'll render our composite image
                RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)all.ActualWidth, (int)all.ActualHeight, 96.0, 96.0, PixelFormats.Pbgra32);

                DrawingVisual dv = new DrawingVisual();
                using (DrawingContext dc = dv.RenderOpen())
                {
                    VisualBrush brush = new VisualBrush(all);
                    dc.DrawRectangle(brush, null, new Rect(new Point(), new Size(all.ActualWidth, all.ActualHeight)));
                }

                renderBitmap.Render(dv);
                // create a png bitmap encoder which knows how to save a .png file
                BitmapEncoder encoder = new PngBitmapEncoder();

                // create frame from the writable bitmap and add to encoder
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));

                string time = DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat);

                string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);

                string path = System.IO.Path.Combine(myPhotos, "KinectScreenshot-Color-" + time + ".png");

                // write the new file to disk
                try
                {
                    // FileStream is IDisposable
                    using (FileStream fs = new FileStream(path, FileMode.Create))
                    {
                        encoder.Save(fs);
                    }
                    status.Content = "照片已保存到" + path;
                    //MessageBox.Show("照片已保存到" + path);
                }
                catch (IOException)
                {
                    status.Content = "照片保存失败";
                   //MessageBox.Show("照片保存失败");
                }
            }
        }

  • 声控

先要下载相应的Speech SDK和 语言包,查看 Kinect Browser 里面Component 要下载的部分。

代码参考 Kinect Browser 里面 Sample C#地最后一个,Speech Basics-WPF

你可能感兴趣的:(kinect开发)