Example #1
0
        private void ThreadProc()
        {
            Imaging.PixelFormat pixelFormat = Imaging.PixelFormat.BGR_24bpp;
            switch (device.GetColorBpp())
            {
            case 24:
                pixelFormat = Imaging.PixelFormat.BGR_24bpp;
                break;

            case 32:
                pixelFormat = Imaging.PixelFormat.BGRX_32bpp;
                break;

            default:
                throw new NotSupportedException("Expected 24bpp or 32bpp image.");
            }
            var  colorImage     = ImagePool.GetOrCreate((int)device.GetColorWidth(), (int)device.GetColorHeight(), pixelFormat);
            uint colorImageSize = device.GetColorHeight() * device.GetColorStride();

            switch (device.GetDepthBpp())
            {
            case 16:
                pixelFormat = Imaging.PixelFormat.Gray_16bpp;
                break;

            case 8:
                pixelFormat = Imaging.PixelFormat.Gray_8bpp;
                break;

            default:
                throw new NotSupportedException("Expected 8bpp or 16bpp image.");
            }
            var  depthImage     = ImagePool.GetOrCreate((int)device.GetDepthWidth(), (int)device.GetDepthHeight(), pixelFormat);
            uint depthImageSize = device.GetDepthHeight() * device.GetDepthStride();

            while (!this.shutdown)
            {
                device.ReadFrame(colorImage.Resource.ImageData, colorImageSize, depthImage.Resource.ImageData, depthImageSize);
                DateTime t = DateTime.Now;
                ColorImage.Post(colorImage, t);
                DepthImage.Post(depthImage, t);
            }
        }