【发布时间】: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