-1

我正在做一个 WPF 应用程序,其中一个功能是从 Kinect 传感器(使用 Aforge 和 SDK 1.5)录制视频(仅 RGB 流)。

在我的应用程序中,我有一个按钮,单击该按钮时,它应该将视频流保存到 avi 文件中。

我添加了引用并将所有 .dll 文件复制到我的项目文件夹中(如其他论坛中所述),但由于某种原因我收到此错误:

{"Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.":null}

所以里面private void button4_Click(object sender, RoutedEventArgs e)是下面的代码:

        int width = 640;
        int height = 480;
        // create instance of video writer
        VideoFileWriter writer = new VideoFileWriter();

        // create new video file
        writer.Open("test.avi", width, height, 25, VideoCodec.MPEG4);

        // create a bitmap to save into the video file
        Bitmap image = new Bitmap (width, height, DrawingColor.PixelFormat.Format24bppRgb);


        for (int i = 0; i < 1000; i++)
        {
            image.SetPixel(i % width, i % height, Color.Red);
            writer.WriteVideoFrame(image);
        }
        writer.Close();
        }

我将非常感谢您的帮助,并且我对记录 RGB 流的方式也很灵活(如果您推荐另一种方式),只要它不复杂,因为我是 C# 新手

4

1 回答 1

1

视频为红色的原因是因为您将其变为红色

    for (int i = 0; i < 1000; i++)
    {
        image.SetPixel(i % width, i % height, Color.Red);
        writer.WriteVideoFrame(image);
    }

您应该做的是转换BitmapSource/ WritableBitmap* (假设您使用BitmapSource或显示 Kinect 的数据WritableBitmap然后您可以将该位图添加到您的视频帧。希望这会有所帮助!

**如果您使用的是 a WritableBitmap请将其转换为 aBitmapImage,然后将其转换为Bitmap*

于 2012-08-29T15:59:25.653 回答