【问题标题】:Bitmap to avi exception位图到 avi 异常
【发布时间】:2012-11-24 08:34:43
【问题描述】:

我正在使用 Simple C# Wrapper for the AviFile Library 和我找到的代码 sn-p here 以便从 Kinect 的色帧创建一个 avi 文件。

我得到了这个异常:“AVIFileOpen 中的异常:-2147205009”

        aviManager = new AviManager(@"C:\temp\temp.avi", false);
        aviStream = aviManager.AddVideoStream(false, 30, _firstBitmap);

上面提到的function生成“_firstBitmap”的地方

Bitmap ImageToBitmap(ColorImageFrame Image)
{
     byte[] pixeldata = new byte[Image.PixelDataLength];
     Image.CopyPixelDataTo(pixeldata);
     Bitmap bmap = new Bitmap(Image.Width, Image.Height, PixelFormat.Format32bppRgb);
     BitmapData bmapdata = bmap.LockBits(
         new Rectangle(0, 0, Image.Width, Image.Height),
         ImageLockMode.WriteOnly, 
         bmap.PixelFormat);
     IntPtr ptr = bmapdata.Scan0;
     Marshal.Copy(pixeldata, 0, ptr, Image.PixelDataLength);
     bmap.UnlockBits(bmapdata);
     return bmap;
 }

颜色帧图像由 Kinect SDK 的 ColorFrameReady 委托提供

private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
    using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
    {
        if (colorFrame != null)
        {
            // Copy the pixel data from the image to a temporary array
            colorFrame.CopyPixelDataTo(this.colorPixels);

            // Write the pixel data into our bitmap
            this.colorBitmap.WritePixels(
                new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                this.colorPixels,
                this.colorBitmap.PixelWidth * sizeof(int),
                0);
            AviManager aviManager = new AviManager(@"C:\temp\temp.avi", false);
            VideoStream aviStream = aviManager.AddVideoStream(false, 30, bmp);

            Bitmap bitmap = ImageToBitmap(colorFrame);
            aviStream.AddFrame(bitmap);
            bitmap.Dispose();
            aviManager.Close();
        }
    }
}

谢谢!

【问题讨论】:

  • _firstBitmap 定义为什么?请包含初始化和声明所有变量的代码。
  • _firstBitmap 是 System.Drawing.Bitmap,它是由上面链接中提到的 ImageToBitmap 函数产生的。
  • 错误是AVIERR_FILEOPEN,您需要查看AVIFileOpen 参数才能了解您遇到此错误的原因。

标签: kinect avi kinect-sdk vfw


【解决方案1】:

AForge.NET 框架提供了多种功能,可让您轻松编写 AVI 或其他视频文件。它还为 Kinect 提供了direct support,让您可以访问摄像机。

但是,根据网站上的信息,它需要libfreenect。我不知道libfreenect 和 office Kinect SDK 是否可以在同一个应用程序中和谐相处。

AVIWriter class 非常简单,不一定需要您使用 AForge.NET 的 Kinect 访问权限。您可以从官方 Kinect SDK 中轻松获取最新的色框,将其转换为 Bitmap 并输出。

【讨论】:

  • 如果 Aforge AVI 编写器和“AviFile 库的简单 C# 包装器”都包装相同的过时 Windows AVI 库,它们有什么区别?
猜你喜欢
  • 2013-04-14
  • 2015-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多