none
depthSourceControl.Source = e.ImageFrame.ToBitmapSource(); an error with code snippet RRS feed

  • Question

  • Hi,
    it's my first time using Kinect, i have tried 

    public MainWindow()
            {
                InitializeComponent();
                Loaded += new RoutedEventHandler(MainWindow_Loaded);
                Unloaded += new RoutedEventHandler(MainWindow_Unloaded);
            }
            void MainWindow_Unloaded(object sender, RoutedEventArgs e)
            {
                nuiRuntime.Uninitialize();
            }
            void MainWindow_Loaded(object sender, RoutedEventArgs e)
            {
                nuiRuntime.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth);
            }
    
            private void buttonCapture_Click(object sender, RoutedEventArgs e)
            {
                nuiRuntime.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nuiRuntime_VideoFrameReady);
                nuiRuntime.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nuiRuntime_DepthFrameReady);
                nuiRuntime.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
                nuiRuntime.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth);
            }
            void nuiRuntime_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
    	    {
                depthSourceControl.Source = e.ImageFrame.ToBitmapSource();
    	    }
            
            void nuiRuntime_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
            {
                PlanarImage planarImage = e.ImageFrame.Image;
                videoControl.Source = BitmapSource.Create(planarImage.Width, planarImage.Height, 96, 96,
                    PixelFormats.Bgr32, null, planarImage.Bits, planarImage.Width * planarImage.BytesPerPixel);
    
                videoSource2.Source = BitmapSource.Create(planarImage.Width, planarImage.Height, 96, 96,
                  PixelFormats.Cmyk32, null, planarImage.Bits, planarImage.Width * planarImage.BytesPerPixel);
     
                videoSource3.Source = BitmapSource.Create(planarImage.Width, planarImage.Height, 96, 96,
    	              PixelFormats.Bgr24, null, planarImage.Bits, planarImage.Width * planarImage.BytesPerPixel);
    	       
            }

    and i got an error message for e.ImageFrame.ToBitmapSource();
    The call is ambiguous between the following methods or properties: 'Coding4Fun.Kinect.Wpf.ImageFrameExtensions.ToBitmapSource(Microsoft.Kinect.ColorImageFrame)' and 'Coding4Fun.Kinect.Wpf.ImageFrameExtensions.ToBitmapSource(Microsoft.Kinect.DepthImageFrame)'

    Please help.

    Wednesday, August 8, 2012 7:20 AM

All replies

  • Have you tried casting your e.ImageFrame.Image to a DepthImageFrame like this:

    (DepthImageFrame)e.ImageFrame.ToBitmapSource();

    Not sure if that will work, but I suspect it might.


    Walt Smith Senior Architect

    Thursday, August 9, 2012 8:19 PM
  • excuse me, I've tried your method,but it didn't work.Could you tell me another method?

    Sunday, August 26, 2012 7:22 AM