AForge.Video.VFW.AVIWriter.AddFrame C# (CSharp) Метод

AddFrame() публичный Метод

Add new frame to the AVI file.

The method adds new video frame to an opened video file. The width and heights of the frame should be the same as it was specified in Open method (see Width and Height properties).

Thrown if no video file was open. Bitmap size must be of the same as video size, which was specified on opening video file. A error occurred while writing new video frame. See exception message.
public AddFrame ( Bitmap frameImage ) : void
frameImage System.Drawing.Bitmap New frame image.
Результат void
        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++;
            }
		}
	}

Usage Example

Пример #1
0
 private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) //обработчик события NewFrame
 {
     if (!stopzapis)
     {
         Bitmap img = (Bitmap)eventArgs.Frame.Clone();
         writer.AddFrame(img);
     }
 }
All Usage Examples Of AForge.Video.VFW.AVIWriter::AddFrame