/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="format">Pixel format of the depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns> public static ImageSource ToBitmap(this DepthImageFrame frame, PixelFormat format, DepthImageMode mode) { short[] pixelData = new short[frame.PixelDataLength]; frame.CopyPixelDataTo(pixelData); byte[] pixels; switch (mode) { case DepthImageMode.Raw: pixels = GenerateRawFrame(frame, pixelData); break; case DepthImageMode.Dark: pixels = GenerateDarkFrame(frame, pixelData); break; case DepthImageMode.Colors: pixels = GenerateColoredFrame(frame, pixelData); break; case DepthImageMode.Player: pixels = GeneratePlayerFrame(frame, pixelData); break; default: pixels = GenerateRawFrame(frame, pixelData); break; } return pixels.ToBitmap(frame.Width, frame.Height, format); }
/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns> public static BitmapSource ToBitmap(this DepthImageFrame frame, DepthImageMode mode) { if (_bitmap == null) { _width = frame.Width; _height = frame.Height; _depthData = new short[frame.PixelDataLength]; _pixels = new byte[_width * _height * Constants.BYTES_PER_PIXEL]; _bitmap = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null); } frame.CopyPixelDataTo(_depthData); switch (mode) { case DepthImageMode.Raw: GenerateRawFrame(); break; case DepthImageMode.Dark: GenerateDarkFrame(); break; case DepthImageMode.Colors: GenerateColoredFrame(); break; case DepthImageMode.Player: GeneratePlayerFrame(); break; default: GenerateRawFrame(); break; } _bitmap.Lock(); Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length); _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height)); _bitmap.Unlock(); return(_bitmap); }
/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns> public static BitmapSource ToBitmap(this DepthImageFrame frame, DepthImageMode mode) { if (_bitmap == null) { _width = frame.Width; _height = frame.Height; _depthData = new short[frame.PixelDataLength]; _pixels = new byte[_width * _height * Constants.BYTES_PER_PIXEL]; _bitmap = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null); } frame.CopyPixelDataTo(_depthData); switch (mode) { case DepthImageMode.Raw: GenerateRawFrame(); break; case DepthImageMode.Dark: GenerateDarkFrame(); break; case DepthImageMode.Colors: GenerateColoredFrame(); break; case DepthImageMode.Player: GeneratePlayerFrame(); break; default: GenerateRawFrame(); break; } _bitmap.Lock(); Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length); _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height)); _bitmap.Unlock(); return _bitmap; }
/// <summary> /// Converts a depth frame to the corresponding System.Drawing.Bitmap. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Drawing.Bitmap representation of the depth frame.</returns> public static Bitmap ToBitmap(this DepthImageFrame frame, DepthImageMode mode) { return(frame.ToBitmap(PixelFormat.Format32bppRgb, mode)); }
/// <summary> /// Converts a depth frame to the corresponding System.Drawing.Bitmap. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="format">Pixel format of the depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Drawing.Bitmap representation of the depth frame.</returns> public static Bitmap ToBitmap(this DepthImageFrame frame, PixelFormat format, DepthImageMode mode) { short[] pixelData = new short[frame.PixelDataLength]; frame.CopyPixelDataTo(pixelData); byte[] pixels; switch (mode) { case DepthImageMode.Raw: pixels = GenerateRawFrame(frame, pixelData); break; case DepthImageMode.Dark: pixels = GenerateDarkFrame(frame, pixelData); break; case DepthImageMode.Colors: pixels = GenerateColoredFrame(frame, pixelData); break; default: pixels = GenerateRawFrame(frame, pixelData); break; } return(pixels.ToBitmap(frame.Width, frame.Height, format)); }
/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns> public static ImageSource ToBitmap(this DepthImageFrame frame, DepthImageMode mode) { return frame.ToBitmap(PixelFormats.Bgr32, mode); }
/// <summary> /// Converts a depth frame to the corresponding System.Drawing.Bitmap. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Drawing.Bitmap representation of the depth frame.</returns> public static Bitmap ToBitmap(this DepthImageFrame frame, DepthImageMode mode) { return frame.ToBitmap(PixelFormat.Format32bppRgb, mode); }
/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns> public static ImageSource ToBitmap(this DepthImageFrame frame, DepthImageMode mode) { return(frame.ToBitmap(PixelFormats.Bgr32, mode)); }