After I connect to USB camera, and read a frame, and convert to bitmap, it crashes after I write bitmap to PictureBox.
I'm developing a Visual Studio 2017 Pro C# Windows forms project.
Also, if I debug process_video_NewFrame() and step through it, then crash 'Parameter is not valid.' occurs at line in Program.cs: Application.Run(new Control_Panel()).
Control_Panel.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using Accord.Video;
using Accord.Video.DirectShow;
namespace ACCORD_WindowsFormsApp9
{
public partial class Control_Panel : Form
{
VideoCaptureDevice videoSource;
Bitmap bitmap;
public Control_Panel()
{
InitializeComponent();
}
private void button_Start_Frame_Captcha_Click(object sender, EventArgs e)
{
var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(process_video_NewFrame);
videoSource.Start();
}
// The video_NewFrame used in the example above could be defined as:
private void process_video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
// get new frame
bitmap = eventArgs.Frame;
System.Windows.Forms.Application.DoEvents();
this.pictureBoxLatestCameraFrame.Image = bitmap;
}
private void button_Stop_Frame_Captcha_Click(object sender, EventArgs e)
{
videoSource.SignalToStop();
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ACCORD_WindowsFormsApp9
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Control_Panel());
}
}
}