适用于Windows的Kinect v2:在c#中调整颜色框的大小

时间:2014-11-06 12:46:09

标签: c# windows sdk frame kinect

任何人都知道,如果可能的话,如何降低色彩流动的kinect帧分辨率?因为我的范围的全高清尺寸太高了。谢谢 我找到了完整高清帧的代码:

private BitmapSource ToBitmap(ColorFrame frame)
    {
        int width = frame.FrameDescription.Width;
        int height = frame.FrameDescription.Height;
        PixelFormat format = PixelFormats.Bgr32;

        byte[] pixels = new byte[width * height * ((PixelFormats.Bgr32.BitsPerPixel + 7) / 8)];

        if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
        {
            frame.CopyRawFrameDataToArray(pixels);
        }
        else
        {
            frame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Bgra);
        }

        int stride = width * format.BitsPerPixel / 8;



        return BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);


    }

1 个答案:

答案 0 :(得分:0)

我已经解决了最后添加此代码的问题

BitmapSource bitmap= BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);
ScaleTransform scale=new ScaleTransform((Width / bitmap.PixelWidth),(Height / bitmap.PixelHeight));
TransformedBitmap tbBitmap = new TransformedBitmap(bitmap, scale);

return tbBitmap;

所以完整的方法是:

private BitmapSource ToBitmap(ColorFrame frame)
    {
        int width = frame.FrameDescription.Width;
        int height = frame.FrameDescription.Height;
        PixelFormat format = PixelFormats.Bgr32;

        byte[] pixels = new byte[width * height * ((PixelFormats.Bgr32.BitsPerPixel + 7) / 8)];

        if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
        {
            frame.CopyRawFrameDataToArray(pixels);
        }
        else
        {
            frame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Bgra);
        }

        int stride = width * format.BitsPerPixel / 8;
        BitmapSource bitmap= BitmapSource.Create(width, height, 96, 96, format, null, pixels, stride);
        ScaleTransform scale=new ScaleTransform((640.0 / bitmap.PixelWidth),(480.0 / bitmap.PixelHeight));
        TransformedBitmap tbBitmap = new TransformedBitmap(bitmap, scale);

        return tbBitmap;
    }