决定尝试使用 AForge处理视频和图像,我尝试实现这个简单的演示:
private void Main_Load(object sender, EventArgs e)
{
// enumerate video devices
FilterInfoCollection videoDevices = new FilterInfoCollection(
FilterCategory.VideoInputDevice);
// create video source
VideoCaptureDevice videoSource = new VideoCaptureDevice(
videoDevices[0].MonikerString);
// set NewFrame event handler
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
// start the video source
videoSource.Start();
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
this.pictureBox1.Image = eventArgs.Frame;
}
问题是我总是得到一个ArgumentException
,尽管并不总是马上发生。它会弹出Application.Run(new Main());
,但堆栈跟踪的顶部如下所示:
at System.Drawing.Image.get_Width() at System.Drawing.Image.get_Size()
at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
不确定这是否相关,但ParamName
异常的属性为空。我尝试将图像分配包装在 try...catch 块中,但这没有帮助。我还检查以确保图像在分配之前不为空。我还检查了非空但 0x0 大小的图像。
我做错了什么?任何人都可以提出解决方法吗?