How to draw video on PictureBox
Products: Video Capture SDK .Net, Video Edit SDK .Net, Media Player SDK .Net
Sample code
-
To draw a video on PictureBox, you must add control to the form. Set the
BackColor
property toBlack
and theSizeMode
property toStretchImage
. -
Add a bool class member called applyingPictureBoxImage on the Start button code and set the applyingPictureBoxImage to false before starting capture or playback.
-
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;
}
- 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.