AForge.Video.DirectShow.VideoCaptureDevice.OnSnapshotFrame C# (CSharp) Method

OnSnapshotFrame() private method

Notifies clients about new snapshot frame.
private OnSnapshotFrame ( Bitmap image ) : void
image Bitmap New snapshot's image.
return void
        private void OnSnapshotFrame( Bitmap image )
        {
            TimeSpan timeSinceStarted = DateTime.Now - startTime;

            // TODO: need to find better way to ignore the first snapshot, which is sent
            // automatically (or better disable it)
            if ( timeSinceStarted.TotalSeconds >= 4 )
            {
                if ( ( !stopEvent.WaitOne( 0, false ) ) && ( SnapshotFrame != null ) )
                    SnapshotFrame( this, new NewFrameEventArgs( image ) );
            }
        }

Usage Example

Beispiel #1
0
 public unsafe int BufferCB(double sampleTime, IntPtr buffer, int bufferLen)
 {
     if (parent.NewFrame != null)
     {
         Bitmap     bitmap     = new Bitmap(width, height, PixelFormat.Format24bppRgb);
         BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
         int        stride     = bitmapData.Stride;
         int        stride2    = bitmapData.Stride;
         byte *     ptr        = (byte *)bitmapData.Scan0.ToPointer() + (long)stride2 * (long)(height - 1);
         byte *     ptr2       = (byte *)buffer.ToPointer();
         for (int i = 0; i < height; i++)
         {
             Win32.memcpy(ptr, ptr2, stride);
             ptr  -= stride2;
             ptr2 += stride;
         }
         bitmap.UnlockBits(bitmapData);
         if (snapshotMode)
         {
             parent.OnSnapshotFrame(bitmap);
         }
         else
         {
             parent.OnNewFrame(bitmap);
         }
         bitmap.Dispose();
     }
     return(0);
 }