//Serializes a depth frame. public static byte[] Serialize(this DepthImageFrame frame) { if (_depthBitmap == null) { _depthWidth = frame.Width; _depthHeight = frame.Height; _depthStride = _depthWidth * Constants.PIXEL_FORMAT.BitsPerPixel / 8; _depthData = new short[frame.PixelDataLength]; _depthPixels = new byte[_depthHeight * _depthWidth * 4]; _depthBitmap = new WriteableBitmap(_depthWidth, _depthHeight, Constants.DPI, Constants.DPI, Constants.PIXEL_FORMAT, null); } frame.CopyPixelDataTo(_depthData); for (int depthIndex = 0, colorIndex = 0; depthIndex < _depthData.Length && colorIndex < _depthPixels.Length; depthIndex++, colorIndex += 4) { //Get the depth value. int depth = _depthData[depthIndex] >> DepthImageFrame.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)); }
//Serializes a color frame. The specified color frame returns a binary representation of the frame 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)); }