public static Bitmap ToBitmap(this short[] depthData, int width, int height, int minimumDistance, Color highlightColor)
        {
            if (depthData != null)
            {
                var colorFrame = new byte[height * width * 4];

                for (int colorIndex = 0, depthIndex = 0; colorIndex < colorFrame.Length; colorIndex += 4, depthIndex++)
                {
                    var intensity = ImageFrameCommonExtensions.CalculateIntensityFromDepth(depthData[depthIndex]);

                    colorFrame[colorIndex + ImageFrameCommonExtensions.RedIndex]   = intensity;
                    colorFrame[colorIndex + ImageFrameCommonExtensions.GreenIndex] = intensity;
                    colorFrame[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = intensity;

                    if (depthData[depthIndex] <= minimumDistance && depthData[depthIndex] > 0)
                    {
                        var mult  = intensity / 255f;
                        var color = Color.FromArgb(
                            (int)(highlightColor.R * mult),
                            (int)(highlightColor.G * mult),
                            (int)(highlightColor.B * mult));

                        colorFrame[colorIndex + ImageFrameCommonExtensions.RedIndex]   = color.R;
                        colorFrame[colorIndex + ImageFrameCommonExtensions.GreenIndex] = color.G;
                        colorFrame[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = color.B;
                    }
                }

                return(colorFrame.ToBitmap(width, height));
            }

            return(null);
        }
        public static Bitmap ToBitmap(this short[] depthData, int width, int height, int minimumDistance, Color highlightColor)
        {
            if (depthData == null)
            {
                return(null);
            }
            //depthData must be array of distances already

            var depthColors = new byte[height * width * 4];

            for (int colorIndex = 0, depthIndex = 0; colorIndex < depthColors.Length; colorIndex += 4, depthIndex++)
            {
                //get the depth, then calculate the intensity (0-255 based on the depth)
                //depth of -1 = dark brown

                if (depthData[depthIndex] == -1)
                {
                    // dark brown
                    depthColors[colorIndex + ImageFrameCommonExtensions.RedIndex]   = 66;
                    depthColors[colorIndex + ImageFrameCommonExtensions.GreenIndex] = 66;
                    depthColors[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = 33;
                }
                else
                {
                    var intensity = ImageFrameCommonExtensions.CalculateIntensityFromDepth(depthData[depthIndex]);

                    depthColors[colorIndex + ImageFrameCommonExtensions.RedIndex]   = intensity;
                    depthColors[colorIndex + ImageFrameCommonExtensions.GreenIndex] = intensity;
                    depthColors[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = intensity;

                    if (depthData[depthIndex] <= minimumDistance && depthData[depthIndex] > 0)
                    {
                        var mult  = intensity / 255f;
                        var color = Color.FromArgb(
                            (int)(highlightColor.R * mult),
                            (int)(highlightColor.G * mult),
                            (int)(highlightColor.B * mult));

                        depthColors[colorIndex + ImageFrameCommonExtensions.RedIndex]   = color.R;
                        depthColors[colorIndex + ImageFrameCommonExtensions.GreenIndex] = color.G;
                        depthColors[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = color.B;
                    }
                }
            }

            return(depthColors.ToBitmap(width, height));
        }