2012-12-06 35 views
0

我使用的是Simple C# Wrapper for the AviFile Library,而我发现的代码片段是here,以便从Kinect的颜色框中创建avi文件。对avi异常的位图

而且我得到这个异常: “异常在AVIFileOpen:-2147205009”

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

凡 “_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; 
} 

提到function和彩色帧图像生成的是由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(); 
     } 
    } 
} 

谢谢!

+0

什么是_firstBitmap定义为?请包括初始化和声明所有变量的代码。 –

+0

_firstBitmap是System.Drawing.Bitmap,它来自上面链接中提到的ImageToBitmap函数。 –

+1

错误是'AVIERR_FILEOPEN',您需要查看'AVIFileOpen'参数以查看您为什么会遇到此错误。 –

回答

1

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

但是,根据网站上的信息,它需要libfreenect。我不知道如果libfreenect和办公室Kinect SDK可以在同一个应用程序中彼此和谐共处。

AVIWriter class是非常直接的,并不一定要求您使用AForge.NET的Kinect访问。您可以轻松从官方Kinect SDK获取最新的颜色框架,将其转换为Bitmap并输出。

+0

如果它们都包装相同的obselete窗口AVI库,那么Aforge AVI writer和“AviFile Library的简单C#包装器”有什么区别? –