1

我正在做 Kinect 编程,当我启用颜色流时,我定义为使用每秒 30 帧的拜耳格式 (ColorImageFormat.RawBayerResolution640x480Fps30)。

渲染图像时,我使用以下代码:

    PixelFormat format = PixelFormats.Bgr32;

    // Bitmap source to write to.
    WriteableBitmap src = new WriteableBitmap((int)_kinectSensor.ColorStream.FrameWidth, (int)_kinectSensor.ColorStream.FrameHeight, 96, 96, format, null);

    // Stride for image.
    var stride = (int)_kinectSensor.ColorStream.FrameWidth * format.BitsPerPixel / 8;

    // Write pixels to bitmap source.
    src.WritePixels(new Int32Rect(0, 0, (int)imgPic.Width, (int)imgPic.Height), rawBayerPixels, stride, 0);

    // Set XAML image source = Bitmap source.
    imgPic.Source = src;

如何根据所选的 ColorImageFormat 在没有上述硬编码的情况下锻炼 PixelFormat?

提前致谢!

4

1 回答 1

0

以防万一有人感兴趣,这就是我最终的做法:

    private PixelFormat GetFormat(ColorImageFormat colFormat)
    {
        // Work out the pixel format depending on the resolution.
        switch (colFormat)
        {
            case ColorImageFormat.InfraredResolution640x480Fps30: return PixelFormats.Gray16;
            case ColorImageFormat.RawYuvResolution640x480Fps15: return PixelFormats.Gray16;
            default: return PixelFormats.Bgr32;
        }
    }
于 2013-09-11T08:57:09.343 回答