已经决定尝试AForge视频和成像的东西,我试图执行this simple demo:更新PictureBox时可能导致ArgumentException的原因是什么?
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大小的图像。
我做错了什么?任何人都可以提出一个解决方法?
异常中的消息是什么? – 2012-04-04 16:16:40
@DavidNelson很好的问题:“参数无效”。 – 2012-04-04 16:18:43
设置eventArgs.Frame时的高度和宽度是多少? – 2012-04-04 16:22:19