Exemple #1
0
        /// <summary>
        /// Opens the next frame in the stream.
        /// </summary>
        /// <param name="millisecondsWait">The timeout (in milliseconds) before returning without a new frame.</param>
        /// <returns>The next frame in the stream.</returns>
        public ImageFrame OpenNextFrame()
        {
            if (streamHandle == IntPtr.Zero)
                throw new KinectException("Open the imagestream first");

            var res = NuiImageStreamGetNextFrame(streamHandle, 100, ref imageFramePtr);

            if (res != HRESULT.S_OK) return null;

            var frame = new NuiImageFrame();
            Marshal.PtrToStructure(imageFramePtr, frame);

            //TODO
            var texture = Marshal.GetDelegateForFunctionPointer(frame.pFrameTexture, typeof(INuiFrameTexture));// = (INuiFrameTexture)Marshal.GetObjectForIUnknown(frame.pFrameTexture);

            var rect = new NuiLockedRect();
            //res = texture.LockRect(0, ref rect, IntPtr.Zero, 0);

            byte[] data = new byte[rect.size];
            Marshal.Copy(rect.pBits, data, 0, (int)rect.size);

            int width = 0;
            int height = 0;

            switch (frame.eResolution) {

                case ImageResolution.Resolution80x60:
                    width = 80;
                    height = 60;
                    break;

                case ImageResolution.Resolution640x480:
                    width = 640;
                    height = 480;
                    break;

                case ImageResolution.Resolution320x240:
                    width = 320;
                    height = 240;
                    break;

                case ImageResolution.Resolution1280x1024:
                    width = 1280;
                    height = 1024;
                    break;

                default:
                    width = 640;
                    height = 480;
                    break;
            }

            ImageFrame imageFrame = new ImageFrame(frame.eImageType, frame.eResolution, height, width, (int)frame.dwFrameNumber, (int)rect.size, (int)frame.liTimeStamp, data);

            res = NuiImageStreamReleaseFrame(streamHandle, imageFramePtr);

            if (res != HRESULT.S_FALSE && res != HRESULT.S_OK)
                throw new KinectException("Failed to release stream.");

            return imageFrame;
        }
Exemple #2
0
 private static extern HRESULT LockRect(uint Level, NuiLockedRect pLockedRect, uint pRect, uint Flags);