Skip to main content

How to draw video on PictureBox

Products: Video Capture SDK .Net, Video Edit SDK .Net, Media Player SDK .Net

Sample code

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

  2. Add a bool class member called applyingPictureBoxImage on the Start button code and set the 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;
}
  1. Add PictureBox clearing to the Stop button code. Code should be called after the SDK control Stop method call.
while (applyingPictureBoxImage)
{
Thread.Sleep(50);
}

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

Required redists

  • SDK redist

Visit our GitHub page to get more code samples.