示例#1
0
        /// <summary>
        /// Serializes a depth frame.
        /// </summary>
        /// <param name="frame">The specified depth frame.</param>
        /// <returns>A binary representation of the frame.</returns>
        public static byte[] Serialize(this DepthFrame frame)
        {
            if (_depthBitmap == null)
            {
                _depthWidth  = frame.FrameDescription.Width;
                _depthHeight = frame.FrameDescription.Height;
                _depthStride = _depthWidth * Constants.PIXEL_FORMAT.BitsPerPixel / 8;
                _depthData   = new ushort[_depthWidth * _depthHeight];
                _depthPixels = new byte[_depthHeight * _depthWidth * (PixelFormats.Bgr32.BitsPerPixel + 7) / 8];
                _depthBitmap = new WriteableBitmap(_depthWidth, _depthHeight, Constants.DPI, Constants.DPI, Constants.PIXEL_FORMAT, null);
            }

            frame.CopyFrameDataToArray(_depthData);

            for (int depthIndex = 0, colorIndex = 0; depthIndex < _depthData.Length && colorIndex < _depthPixels.Length; depthIndex++, colorIndex += 4)
            {
                // Get the depth value.
                int depth = _depthData[depthIndex] >> PlayerIndexBitmaskWidth;

                // Equal coloring for monochromatic histogram.
                byte intensity = (byte)(255 - (255 * Math.Max(depth - Constants.MIN_DEPTH_DISTANCE, 0) / (Constants.MAX_DEPTH_DISTANCE_OFFSET)));

                _depthPixels[colorIndex + 0] = intensity;
                _depthPixels[colorIndex + 1] = intensity;
                _depthPixels[colorIndex + 2] = intensity;
            }

            _depthBitmap.WritePixels(new Int32Rect(0, 0, _depthWidth, _depthHeight), _depthPixels, _depthStride, 0);

            return(FrameSerializer.CreateBlob(_depthBitmap, Constants.CAPTURE_FILE_DEPTH));
        }
示例#2
0
        /// <summary>
        /// Serializes a color frame.
        /// </summary>
        /// <param name="frame">The specified color frame.</param>
        /// <returns>A binary representation of the frame.</returns>
        public static byte[] Serialize(this ColorImageFrame frame)
        {
            if (_colorBitmap == null)
            {
                _colorWidth  = frame.Width;
                _colorHeight = frame.Height;
                _colorStride = _colorWidth * Constants.PIXEL_FORMAT.BitsPerPixel / 8;
                _colorPixels = new byte[frame.PixelDataLength];
                _colorBitmap = new WriteableBitmap(_colorWidth, _colorHeight, Constants.DPI, Constants.DPI, Constants.PIXEL_FORMAT, null);
            }

            frame.CopyPixelDataTo(_colorPixels);

            _colorBitmap.WritePixels(new Int32Rect(0, 0, _colorWidth, _colorHeight), _colorPixels, _colorStride, 0);

            return(FrameSerializer.CreateBlob(_colorBitmap, Constants.CAPTURE_FILE_COLOR));
        }
        /// <summary>
        /// Serializes a color frame.
        /// </summary>
        /// <param name="frame">The specified color frame.</param>
        /// <returns>A binary representation of the frame.</returns>
        public static byte[] Serialize(this ColorFrame frame)
        {
            if (_colorBitmap == null)
            {
                _colorWidth  = frame.FrameDescription.Width;
                _colorHeight = frame.FrameDescription.Height;
                _colorStride = _colorWidth * Constants.PIXEL_FORMAT.BitsPerPixel / 8;
                _colorPixels = new byte[_colorHeight * _colorWidth * ((PixelFormats.Bgr32.BitsPerPixel + 7) / 8)];
                _colorBitmap = new WriteableBitmap(_colorWidth, _colorHeight, Constants.DPI, Constants.DPI, Constants.PIXEL_FORMAT, null);
            }

            if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
            {
                frame.CopyRawFrameDataToArray(_colorPixels);
            }
            else
            {
                frame.CopyConvertedFrameDataToArray(_colorPixels, ColorImageFormat.Bgra);
            }

            _colorBitmap.WritePixels(new Int32Rect(0, 0, _colorWidth, _colorHeight), _colorPixels, _colorStride, 0);

            return(FrameSerializer.CreateBlob(_colorBitmap, Constants.CAPTURE_FILE_COLOR));
        }