How to draw video on PictureBox in .Net SDKs?

Sample code

1. To draw a video on PictureBox, you need to add control to the form. Set BackColor property to Black and SizeMode property to StretchImage.

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

3. Implement the OnVideoFrameBitmap event to draw the frame.

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 the Stop button code. Code should be called after SDK control Stop method call.

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

pictureBox1.Image?.Dispose();
pictureBox1.Image = null;
Please contact support to get help with this tutorial. Visit our GitHub page to get more code samples.
abstract 2abstract 1abstract 3
logo
VisioForge © 2006 - 2021