Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Kinect v2 for windows:在c中调整颜色框的大小_C#_Windows_Sdk_Frame_Kinect - Fatal编程技术网

C# Kinect v2 for windows:在c中调整颜色框的大小

C# Kinect v2 for windows:在c中调整颜色框的大小,c#,windows,sdk,frame,kinect,C#,Windows,Sdk,Frame,Kinect,有人知道,如果可能的话,如何降低彩色流的kinect帧分辨率?因为全高清尺寸对我的范围来说太高了。谢谢 我找到了全高清帧的代码: private BitmapSource ToBitmap(ColorFrame frame) { int width = frame.FrameDescription.Width; int height = frame.FrameDescription.Height; PixelFormat format =

有人知道,如果可能的话,如何降低彩色流的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);


    }

我已决定在末尾添加此代码

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;
    }

为了使用BitmapSource和PixelFormats以及BitsPerPixel,您提供了哪些参考资料?很抱歉,我已经没有该项目了,但我认为它们在System.Windows.media中