src/Foundation/Media/Gimela.Media.Video.VFW/AVIWriter.cs
/// <summary>
/// Add new frame to the AVI file.
/// </summary>
/// 
/// <param name="frameImage">New frame image.</param>
/// 
/// <remarks><para>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 <see cref="Open"/> method
/// (see <see cref="Width"/> and <see cref="Height"/> properties).</para></remarks>
/// 
/// <exception cref="ApplicationException">Failure of opening video files (the exception message
/// specifies the issues).</exception>
/// 
Add new frame to the AVI file.
Add new frame to the AVI file .
public void AddFrame(Bitmap frameImage)
    {
      lock (this)
      {
        if (buffer == IntPtr.Zero)
          throw new ApplicationException("AVI file should be successfully opened before writing");
        if ((frameImage.Width != width) || (frameImage.Height != height))
          throw new ApplicationException("Invalid image dimension");
        BitmapData imageData = frameImage.LockBits(
            new Rectangle(0, 0, width, height),
            ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
        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(new IntPtr(dst), new IntPtr(src), (UIntPtr)dstStride);
          dst += dstStride;
          src -= srcStride;
        }
        frameImage.UnlockBits(imageData);
        if (Win32.AVIStreamWrite(streamCompressed, position, 1, buffer,
            stride * height, 0, IntPtr.Zero, IntPtr.Zero) != 0)
          throw new ApplicationException("Failed adding frame");
        position++;
      }
    }
public void AddFrame ( Bitmap frameImage ) { lock ( this ) { if ( buffer == IntPtr . Zero ) throw new ApplicationException ( " " ) ; if ( ( frameImage . Width != width ) || ( frameImage . Height != height ) ) throw new ApplicationException ( " " ) ; BitmapData imageData = frameImage . LockBits ( new Rectangle ( 0 , 0 , width , height ) , ImageLockMode . ReadOnly , PixelFormat . Format24bppRgb ) ; 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 ( new IntPtr ( dst ) , new IntPtr ( src ) , ( UIntPtr ) dstStride ) ; dst += dstStride ; src -= srcStride ; } frameImage . UnlockBits ( imageData ) ; if ( Win32 . AVIStreamWrite ( streamCompressed , position , 1 , buffer , stride * height , 0 , IntPtr . Zero , IntPtr . Zero ) != 0 ) throw new ApplicationException ( " " ) ; position ++ ; } }
Add new frame to the AVI file.
Add new frame to the AVI file .
// check if AVI file was properly opened // check image dimension // lock bitmap data // copy image data // unlock bitmap data // write to stream
Failure of opening video files (the exception message
specifies the issues).
Failure of opening video files ( the exception message specifies the issues ) .
frameImage
Bitmap
New frame image.
New frame image .
remarks
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  method
.
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 method .