我使用fallowing库来检测网络摄像头以获得简单的c#应用程序。当它调试工作正常,当我再次尝试它给出了一个错误。
Used reference 如果有人对此有任何想法,请帮我解决。
First get this box ,点击“确定”后会收到错误消息。
捕获视频图像时发生错误。视频捕捉 现在将被终止。对象引用未设置为的实例 对象
Form1.cs的
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using WinFormCharpWebCam;
namespace camTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
WebCam webcam;
private void button1_Click(object sender, EventArgs e)
{
webcam.Start();
}
private void button2_Click(object sender, EventArgs e)
{
webcam.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
webcam.Continue();
}
private void Form1_Load(object sender, EventArgs e)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref imgVideo);
}
}
}
Webcam.cs
using System;
using System.IO;
using System.Linq;
using System.Text;
using WebCam_Capture;
using System.Collections.Generic;
namespace WinFormCharpWebCam
{
//Design by Pongsakorn Poosankam
class WebCam
{
private WebCamCapture webcam;
private System.Windows.Forms.PictureBox _FrameImage;
private int FrameNumber = 30;
public void InitializeWebCam(ref System.Windows.Forms.PictureBox ImageControl)
{
webcam = new WebCamCapture();
webcam.FrameNumber = ((ulong)(0ul));
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.ImageCaptured += new WebCamCapture.WebCamEventHandler(webcam_ImageCaptured);
_FrameImage = ImageControl;
}
void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
_FrameImage.Image = e.WebCamImage;
}
public void Start()
{
webcam.TimeToCapture_milliseconds = FrameNumber;
webcam.Start(0);
}
public void Stop()
{
webcam.Stop();
}
public void Continue()
{
// change the capture time frame
webcam.TimeToCapture_milliseconds = FrameNumber;
// resume the video capture from the stop
webcam.Start(this.webcam.FrameNumber);
}
public void ResolutionSetting()
{
webcam.Config();
}
public void AdvanceSetting()
{
webcam.Config2();
}
}
}