コード例 #1
0
        /// <summary>
        /// レンダリング時にKinectデータを取得し描画
        /// </summary>
        private void compositionTarget_rendering(object sender, EventArgs e)
        {
            //フレームを読み取る
            HRESULT hr = NuiImageStreamGetNextFrame(streamHandle, 0, ref imageFramePtr);
            if (hr != HRESULT.S_OK)
            {
                return;
            }

            try
            {
                //imageFramePtrからNUI_IMAGE_FRAMEへマーシャリング
                var nativeImageFrame = new NUI_IMAGE_FRAME();
                Marshal.PtrToStructure(imageFramePtr, nativeImageFrame);

                //Console.WriteLine("SizeOf: {0}", Marshal.SizeOf(typeof(NUI_IMAGE_FRAME)));

                //pFrameTextureからINuiFrameTextureへマーシャリング
                var pTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(nativeImageFrame.pFrameTexture);

                var BufferLen = pTexture.BufferLen();
                var Pitch = pTexture.Pitch();

                /*
                 *
                //ロックしてバッファへアクセス
                var LockedRect = new NUI_LOCKED_RECT();
                //var Rect = new RECT();

                IntPtr pLockedRect = IntPtr.Zero;
                IntPtr pRect = IntPtr.Zero;
                pTexture.LockRect(0, ref pLockedRect, ref pRect, 0);

                Marshal.PtrToStructure(pLockedRect, LockedRect);

                */
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Message: " + ex.Message);
            }
            finally
            {
                var res = NuiImageStreamReleaseFrame(streamHandle, imageFramePtr);
                if (res != HRESULT.S_FALSE && res != HRESULT.S_OK)
                {
                    throw new InvalidOperationException("Failed to release stream, HRESULT: " + res.ToString());
                }
            }
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: sugasaki/Kinect
        /// <summary>
        /// レンダリング時にKinectデータを取得し描画
        /// </summary>
        private void compositionTarget_rendering(object sender, EventArgs e)
        {
            //フレームを読み取る
            HRESULT hr = NuiImageStreamGetNextFrame(streamHandle, 0, ref imageFramePtr);
            if (hr != HRESULT.S_OK)
            {
                return;
            }

            //フレームポインタからNUI_IMAGE_FRAMEへ変換
            var nativeImageFrame = new NUI_IMAGE_FRAME();
            Marshal.PtrToStructure(imageFramePtr, nativeImageFrame);

            //pFrameTextureからINuiFrameTextureへ変換
            //var pTexture = new NativePlanarImage();
            //Marshal.PtrToStructure(nativeImageFrame.pFrameTexture, pTexture);

            //dynamic pTexture = nativeImageFrame.pFrameTexture;
            //Marshal.PtrToStructure(nativeImageFrame.pFrameTexture, pTexture);

            ////
            IntPtr pLockedRect = IntPtr.Zero;
            IntPtr pRect = IntPtr.Zero;
            pTexture.LockRect(0, ref pLockedRect, ref pRect, 0);

            //var LockedRect = new NUI_LOCKED_RECT();

            //if ( LockedRect.Pitch != 0 )
            //{
            //    m_pDrawColor->Draw( static_cast<BYTE *>(LockedRect.pBits), LockedRect.size );
            //}
            //else
            //{
            //    OutputDebugString( L"Buffer length of received texture is bogus\r\n" );
            //}

            //pTexture->UnlockRect( 0 );

            //m_pNuiSensor->NuiImageStreamReleaseFrame( m_pVideoStreamHandle, &imageFrame );

            //INuiFrameTexture* pTexture = imageFrame.pFrameTexture;

            //image1.Source = ToBitmapSource();

            NuiShutdown();
        }