How to draw video on PictureBox?

1. Add PictureBox control to form. Set BackColor property to Black and SizeMode property to StretchImage.

2. Add bool class member called applyingPictureBoxImage. On Start button code set applyingPictureBoxImage to false before starting capture or playback.

3. Implement OnVideoFrameBitmap event to draw video frame on PictureBox.

private void VideoCapture1_OnVideoFrameBitmap(object sender, VideoFrameBitmapEventArgs e)
        {
            if (applyingPictureBoxImage)
            {
                return;
            }

            applyingPictureBoxImage = true;

            var image = pictureBox1.Image;
            pictureBox1.Image = new Bitmap(e.Frame);

            image?.Dispose();
            
            applyingPictureBoxImage = false;
        }

4. Add PictureBox clearing to Stop button code. Code should be called after SDK control Stop method call.

while (applyingPictureBoxImage)
            {
                Thread.Sleep(50);
            }

pictureBox1.Image?.Dispose();
pictureBox1.Image = null;

VisioForge © 2006-2020

  • GitHub-Mark-64px
  • Twitter Социальные Иконка
  • VisioForge Facebook page
  • YouTube channel