public void AddFrame( Bitmap frameImage )
{
lock ( sync )
{
// check if AVI file was properly opened
if ( buffer == IntPtr.Zero )
throw new System.IO.IOException( "AVI file should be successfully opened before writing." );
// check image dimension
if ( ( frameImage.Width != width ) || ( frameImage.Height != height ) )
throw new ArgumentException( "Bitmap size must be of the same as video size, which was specified on opening video file." );
// lock bitmap data
BitmapData imageData = frameImage.LockBits(
new Rectangle( 0, 0, width, height ),
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb );
// copy image data
int srcStride = imageData.Stride;
int dstStride = stride;
int src = imageData.Scan0.ToInt32( ) + srcStride * ( height - 1 );
int dst = buffer.ToInt32( );
for ( int y = 0; y < height; y++ )
{
Win32.memcpy( dst, src, dstStride );
dst += dstStride;
src -= srcStride;
}
// unlock bitmap data
frameImage.UnlockBits( imageData );
// write to stream
if ( Win32.AVIStreamWrite( streamCompressed, position, 1, buffer,
stride * height, 0, IntPtr.Zero, IntPtr.Zero ) != 0 )
throw new VideoException( "Failed adding frame." );
position++;
}
}
}