src/Foundation/Media/Gimela.Media.Video.VFW/AVIReader.cs
/// <summary>
/// Get next frame of opened video stream.
/// </summary>
/// 
/// <returns>Returns next frame as a bitmap.</returns>
/// 
/// <remarks><para>The method reads and returns the next video frame in the opened video stream
/// at the position, which is set in <see cref="Position"/> property.</para></remarks>
/// 
/// <exception cref="ApplicationException">Failure of opening video files (the exception message
/// specifies the issues).</exception>
/// 
Get next frame of opened video stream.
Get next frame of opened video stream .
public Bitmap GetNextFrame()
    {
      lock (this)
      {
        IntPtr DIB = Win32.AVIStreamGetFrame(getFrame, position);
        if (DIB == IntPtr.Zero)
          throw new ApplicationException("Failed getting frame");
        Win32.BITMAPINFOHEADER bitmapInfoHeader;
        bitmapInfoHeader = (Win32.BITMAPINFOHEADER)Marshal.PtrToStructure(DIB, typeof(Win32.BITMAPINFOHEADER));
        Bitmap image = new Bitmap(width, height, PixelFormat.Format24bppRgb);
        BitmapData imageData = image.LockBits(
            new Rectangle(0, 0, width, height),
            ImageLockMode.ReadWrite,
            PixelFormat.Format24bppRgb);
        int srcStride = imageData.Stride;
        int dstStride = imageData.Stride;
        if (bitmapInfoHeader.height > 0)
        {
          int dst = imageData.Scan0.ToInt32() + dstStride * (height - 1);
          int src = DIB.ToInt32() + Marshal.SizeOf(typeof(Win32.BITMAPINFOHEADER));
          for (int y = 0; y < height; y++)
          {
            Win32.memcpy(new IntPtr(dst), new IntPtr(src), (UIntPtr)srcStride);
            dst -= dstStride;
            src += srcStride;
          }
        }
        else
        {
          int dst = imageData.Scan0.ToInt32();
          int src = DIB.ToInt32() + Marshal.SizeOf(typeof(Win32.BITMAPINFOHEADER));
          Win32.memcpy(new IntPtr(dst), new IntPtr(src), (UIntPtr)(srcStride * height));
        }
        image.UnlockBits(imageData);
        position++;
        return image;
      }
    }
public Bitmap GetNextFrame ( ) { lock ( this ) { IntPtr DIB = Win32 . AVIStreamGetFrame ( getFrame , position ) ; if ( DIB == IntPtr . Zero ) throw new ApplicationException ( " " ) ; Win32 . BITMAPINFOHEADER bitmapInfoHeader ; bitmapInfoHeader = ( Win32 . BITMAPINFOHEADER ) Marshal . PtrToStructure ( DIB , typeof ( Win32 . BITMAPINFOHEADER ) ) ; Bitmap image = new Bitmap ( width , height , PixelFormat . Format24bppRgb ) ; BitmapData imageData = image . LockBits ( new Rectangle ( 0 , 0 , width , height ) , ImageLockMode . ReadWrite , PixelFormat . Format24bppRgb ) ; int srcStride = imageData . Stride ; int dstStride = imageData . Stride ; if ( bitmapInfoHeader . height > 0 ) { int dst = imageData . Scan0 . ToInt32 ( ) + dstStride * ( height - 1 ) ; int src = DIB . ToInt32 ( ) + Marshal . SizeOf ( typeof ( Win32 . BITMAPINFOHEADER ) ) ; for ( int y = 0 ; y < height ; y ++ ) { Win32 . memcpy ( new IntPtr ( dst ) , new IntPtr ( src ) , ( UIntPtr ) srcStride ) ; dst -= dstStride ; src += srcStride ; } } else { int dst = imageData . Scan0 . ToInt32 ( ) ; int src = DIB . ToInt32 ( ) + Marshal . SizeOf ( typeof ( Win32 . BITMAPINFOHEADER ) ) ; Win32 . memcpy ( new IntPtr ( dst ) , new IntPtr ( src ) , ( UIntPtr ) ( srcStride * height ) ) ; } image . UnlockBits ( imageData ) ; position ++ ; return image ; } }
Get next frame of opened video stream.
Get next frame of opened video stream .
// get frame at specified position // copy BITMAPINFOHEADER from unmanaged memory // create new bitmap // lock bitmap data // copy image data // check image direction // it`s a bottom-top image // it`s a top bootom image // copy the whole image // unlock bitmap data // move position to the next frame
Returns next frame as a bitmap.
Returns next frame as a bitmap .
Failure of opening video files (the exception message
specifies the issues).
Failure of opening video files ( the exception message specifies the issues ) .
remarks
The method reads and returns the next video frame in the opened video stream
at the position, which is set in  property.
The method reads and returns the next video frame in the opened video stream at the position which is set in property .