Exemplo n.º 1
0
        public ColorFrame(Microsoft.Kinect.ColorFrame cf)
        {
            Type = FrameType.Color;

            underlyingColorFrame = cf;

            FrameDescription cfd = underlyingColorFrame.CreateFrameDescription(ColorImageFormat.Bgra);

            Width  = cfd.Width;
            Height = cfd.Height;

            // Stride is the number of bytes allocated for one scanline of the bitmap
            // Fact: Scanlines must be aligned on 32-bit boundaries
            // So, each scanline may have padded bytes at the end to ensure this
            // so stride is: ((w * bitsPerPixel + (padBits-1)) / padBits) * padToNBytes
            // where padBits = 8 * padToNBytes
            // See https://msdn.microsoft.com/en-us/library/windows/desktop/aa473780(v=vs.85).aspx
            stride = (Width * PixelFormats.Bgra32.BitsPerPixel + 7) / 8;

            if (colorData == null)
            {
                colorData = new byte[stride * Height];

                using (KinectBuffer colorBuffer = cf.LockRawImageBuffer())
                {
                    // TODO: crop and convert to jpeg.
                    underlyingColorFrame.CopyConvertedFrameDataToArray(colorData, ColorImageFormat.Bgra);
                }

                colorDataBitmap = new Bitmap(Width, Height, stride,
                                             System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                                             Marshal.UnsafeAddrOfPinnedArrayElement(colorData, 0));
            }
        }
Exemplo n.º 2
0
 public void CopyFramePixelDataToArray(byte[] buffer)
 {
     _colorFrame.CopyConvertedFrameDataToArray(buffer, ColorImageFormat.Bgra);
 }