已經決定嘗試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