I am using the Simple C# Wrapper for the AviFile Library, and the code snippet I found here in order create an avi file from Kinect's color frames.
And I get this exception: "Exception in AVIFileOpen: -2147205009"
aviManager = new AviManager(@"C:\temp\temp.avi", false);
aviStream = aviManager.AddVideoStream(false, 30, _firstBitmap);
Where the "_firstBitmap" is generated with the function mentioned above
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;
}
And the Color frame image is provided from the Kinect SDK's ColorFrameReady delegate
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();
}
}
}
Thank you !