C# 使用网络摄像头时出现NullReferenceException
我正在为大学制作一个C#软件,我需要这方面的帮助: 使用的Youtube教程: 捕获视频图像时出错。视频捕获 现在将被终止。对象引用未设置为的实例 反对 第一次执行软件时,它工作得很好,现在当我再次关闭和打开时,出现了这个错误(似乎有一个进程正在运行)。 我看了youtube上的一篇教程,我注意到有很多抱怨是因为类似的错误。 是的,但只有当你按下3次“开始”按钮时,我才知道错误 代码: FRM: Webcam.cs:C# 使用网络摄像头时出现NullReferenceException,c#,webcam,nullreferenceexception,C#,Webcam,Nullreferenceexception,我正在为大学制作一个C#软件,我需要这方面的帮助: 使用的Youtube教程: 捕获视频图像时出错。视频捕获 现在将被终止。对象引用未设置为的实例 反对 第一次执行软件时,它工作得很好,现在当我再次关闭和打开时,出现了这个错误(似乎有一个进程正在运行)。 我看了youtube上的一篇教程,我注意到有很多抱怨是因为类似的错误。 是的,但只有当你按下3次“开始”按钮时,我才知道错误 代码: FRM: Webcam.cs: { class WebCam { priv
{
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 ResolutionSetting()
{
webcam.Config();
}
public void AdvanceSetting()
{
webcam.Config2();
}
}
}
Helper.cs
class Helper
{
public static void SaveImageCapture(System.Drawing.Image image)
{
SaveFileDialog s = new SaveFileDialog();
s.FileName = "Image";// Default file name
s.DefaultExt = ".Jpg";// Default file extension
s.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension
// Show save file dialog box
// Process save file dialog box results
if (s.ShowDialog()==DialogResult.OK)
{
// Save Image
string filename = s.FileName;
FileStream fstream = new FileStream(filename, FileMode.Create);
image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
fstream.Close();
}
}
}
杀死使用网络摄像头的其他应用程序(如Skype)的进程,您的代码将运行。:) 您找到解决此问题的方法了吗?是否有其他与此错误相关的堆栈跟踪信息?行号还是方法名?这些都是很好的线索,有助于关注错误的来源。现在我也有同样的问题。有没有人可以帮忙?几乎所有的
NullReferenceException
案例都是一样的。有关提示,请参阅“”。
class Helper
{
public static void SaveImageCapture(System.Drawing.Image image)
{
SaveFileDialog s = new SaveFileDialog();
s.FileName = "Image";// Default file name
s.DefaultExt = ".Jpg";// Default file extension
s.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension
// Show save file dialog box
// Process save file dialog box results
if (s.ShowDialog()==DialogResult.OK)
{
// Save Image
string filename = s.FileName;
FileStream fstream = new FileStream(filename, FileMode.Create);
image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
fstream.Close();
}
}
}