1: private void ProcessColorFrame(bool hasColor)
2: {
3: if (!hasColor) return;
4: // Write the pixel data into our bitmap
5: _colorBitmap.WritePixels(new Int32Rect(0, 0, _colorBitmap.PixelWidth, _colorBitmap.PixelHeight), _colorPixels,
6: _colorBitmap.PixelWidth*sizeof (int), 0);
7:
8: if (_playerOpacityMaskImage == null)
9: {
10: _playerOpacityMaskImage = new WriteableBitmap(_depthWidth, _depthHeight, 96, 96, PixelFormats.Bgra32, null);
11: imgMask.OpacityMask = new ImageBrush
12: {
13: ImageSource = _playerOpacityMaskImage
14: };
15: }
16:
17: _playerOpacityMaskImage.WritePixels(new Int32Rect(0, 0, _depthWidth, _depthHeight), _greenScreenPixelData,
18: _depthWidth*((_playerOpacityMaskImage.Format.BitsPerPixel + 7)/8), 0);
19: }
20:
21: private void ProcessDepthFrame(bool hasDepth)
22: {
23: if (hasDepth)
24: {
25: _sensor.MapDepthFrameToColorFrame(DepthImageFormat.Resolution320x240Fps30, _depthPixels,
26: ColorImageFormat.RgbResolution640x480Fps30, _colorCoordinates);
27:
28: Array.Clear(_greenScreenPixelData, 0, _greenScreenPixelData.Length);
29:
30: for (var y = 0; y < _depthHeight; ++y)
31: {
32: for (var x = 0; x < _depthWidth; ++x)
33: {
34: var depthIndex = x + (y*_depthWidth);
35: var depthPixel = _depthPixels[depthIndex];
36: var player = depthPixel & DepthImageFrame.PlayerIndexBitmask;
37: if (player <= 0) continue;
38:
39: var colorImagePoint = _colorCoordinates[depthIndex];
40: var colorInDepthX = colorImagePoint.X/_colorToDepthDivisor;
41: var colorInDepthY = colorImagePoint.Y/_colorToDepthDivisor;
42: if (colorInDepthX <= 0 || colorInDepthX >= _depthWidth || colorInDepthY < 0 ||
43: colorInDepthY >= _depthHeight) continue;
44: var greenScreenIndex = colorInDepthX + (colorInDepthY*_depthWidth);
45: _greenScreenPixelData[greenScreenIndex] = OpaquePixelValue;
46: _greenScreenPixelData[greenScreenIndex - 1] = OpaquePixelValue;
47: }
48: }
49: }
50: }
51:
52: private bool GetColorFrame(AllFramesReadyEventArgs e)
53: {
54: bool hasColor;
55: using (var colorFrame = e.OpenColorImageFrame())
56: {
57: if (colorFrame != null)
58: {
59: colorFrame.CopyPixelDataTo(_colorPixels);
60: hasColor = true;
61: }
62: }
63: return hasColor;
64: }
65:
66: private bool GetDepthFrame(AllFramesReadyEventArgs e)
67: {
68: bool hasDepth;
69: using (var depthFrame = e.OpenDepthImageFrame())
70: {
71: if (depthFrame != null)
72: {
73: depthFrame.CopyPixelDataTo(_depthPixels);
74: hasDepth = true;
75: }
76: }
77: return hasDepth;
78: }