C# 为什么没有';你没有拿起相机吗?
我在做条形码扫描器,但“视频捕获设备不能拾取任何物体”? 我在visual studio 2019 C中使用了一个RGE视频和ZXing# 我希望它能够扫描我的笔记本电脑网络摄像头的条形码。 我试着用这个问题来运行它,但是在我的组合框中,应该有相机可以使用,但是没有。我甚至试着在打开程序之前激活网络摄像头。 代码:C# 为什么没有';你没有拿起相机吗?,c#,camera,barcode,barcode-scanner,C#,Camera,Barcode,Barcode Scanner,我在做条形码扫描器,但“视频捕获设备不能拾取任何物体”? 我在visual studio 2019 C中使用了一个RGE视频和ZXing# 我希望它能够扫描我的笔记本电脑网络摄像头的条形码。 我试着用这个问题来运行它,但是在我的组合框中,应该有相机可以使用,但是没有。我甚至试着在打开程序之前激活网络摄像头。 代码: 我一直收到此错误消息:System.NullReferenceException:对象引用未设置为对象实例。好的,我已对其进行了更深入的检查。此错误是从那些nuget包引发的。因此,
我一直收到此错误消息:System.NullReferenceException:对象引用未设置为对象实例。好的,我已对其进行了更深入的检查。此错误是从那些nuget包引发的。因此,要找到解决方案,您需要调试它们。我不断收到以下错误消息:System.NullReferenceException:对象引用未设置为对象实例。好的,我已对其进行了更深入的检查。此错误是从那些nuget包中引发的。因此,要找到解决方案,您需要调试它们
FilterInfoCollection FilterInfoCollection;
VideoCaptureDevice VideoCaptureDevice;
private void Form1_Load(object sender, EventArgs e)
{
FilterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo device in FilterInfoCollection)
comboBox1.Items.Add(device.Name);
comboBox1.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
VideoCaptureDevice = new VideoCaptureDevice(FilterInfoCollection[comboBox1.SelectedIndex].MonikerString);
VideoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame;
VideoCaptureDevice.Start();
}
private void VideoCaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
BarcodeReader reader = new BarcodeReader();
var result = reader.Decode(bitmap);
if (result != null)
{
textBox1.Invoke(new MethodInvoker(delegate ()
{
textBox1.Text = result.ToString();
}));
}
pictureBox1.Image = bitmap;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (VideoCaptureDevice != null)
{
if (VideoCaptureDevice.IsRunning)
VideoCaptureDevice.Stop();
}
}
}
}