Ejemplo n.º 1
0
        public ColorFrame(Windows.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 * 32 + 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));
            }
        }
Ejemplo n.º 2
0
    private Bitmap ColorImageFrameToBitmap(Windows.Kinect.ColorFrame colorFrame)
    {
        colorFrame.CreateFrameDescription(ColorImageFormat.Yuy2);

        byte[] pixelBuffer = new byte[
            colorFrame.FrameDescription.Width *
            colorFrame.FrameDescription.Height *
            colorFrame.FrameDescription.BytesPerPixel];

        colorFrame.CopyConvertedFrameDataToArray(
            pixelBuffer, ColorImageFormat.Yuy2);
        Bitmap bitmapFrame = ArrayToBitmap(pixelBuffer, colorFrame.FrameDescription.Width, colorFrame.FrameDescription.Height, PixelFormat.Format32bppRgb);

        return(bitmapFrame);
    }