public static Bitmap ToBitmap(this ImageFrame image) { if (image == null) { throw new ArgumentNullException("image"); } switch (image.Type) { case ImageType.Color: { return(image.Image.Bits.ToBitmap(image.Image.Width, image.Image.Height)); } case ImageType.Depth: { return(ImageFrameCommonExtensions.ConvertDepthFrameDataToBitmapData(image.Image.Bits, image.Image.Width, image.Image.Height).ToBitmap(image.Image.Width, image.Image.Height)); } case ImageType.DepthAndPlayerIndex: { return(ImageFrameCommonExtensions.ConvertDepthFrameDataWithSkeletonToBitmapData(image.Image.Bits, image.Image.Width, image.Image.Height).ToBitmap(image.Image.Width, image.Image.Height)); } default: return(null); } }
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 DepthImageFrame image) { short[] rawDepth = new short[image.PixelDataLength]; image.CopyPixelDataTo(rawDepth); return(ImageFrameCommonExtensions.ConvertDepthFrameToBitmap(image).ToBitmap(image.Width, image.Height)); //return ImageFrameCommonExtensions.ConvertDepthFrameDataToBitmapData(image.Image.Bits, image.Image.Width, image.Image.Height).ToBitmap(image.Image.Width, image.Image.Height); }
public static BitmapSource ToBitmapSource(this DepthImageFrame image) { if (image == null) { return(null); } var bytes = ImageFrameCommonExtensions.ConvertDepthFrameToBitmap(image); return(bytes.ToBitmapSource(image.Width, image.Height)); }
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)); }
public static int GetDistance(this DepthImageFrame image, int x, int y) { return(ImageFrameCommonExtensions.GetDistance(image, x, y)); }
public static short[] ToDepthArray(this DepthImageFrame image) { return(ImageFrameCommonExtensions.ToDepthArray(image)); }
public static short GetDistance(this ImageFrame image, int x, int y) { return ImageFrameCommonExtensions.GetDistance(image, x, y); }
public static short[][] ToDepthArray2D(this ImageFrame image) { return ImageFrameCommonExtensions.ToDepthArray2D(image); }