Dear All Programmer,
I tried in the project in vb.net there is an Error but if I run it in the c# project there is no error. Is there a problem with my vb.net code?.is there another solution so that there is no error in the vb.net project?
Thanks
'this is the result of an error from project vb.net
Error 3 Argument not specified for parameter 'sender' of 'Private Sub VideoCaptureDevice_NewFrame(sender As Object, eventArgs As AForge.Video.NewFrameEventArgs)'. C:\Users\Admin\documents\visual studio 2012\Projects\Barcode Scanner using Webcam in VB.NET\Barcode Scanner using Webcam in VB.NET\Form1.vb 16 40 Barcode Scanner using Webcam in VB.NET
Error 2 Argument not specified for parameter 'eventArgs' of 'Private Sub VideoCaptureDevice_NewFrame(sender As Object, eventArgs As AForge.Video.NewFrameEventArgs)'. C:\Users\Admin\documents\visual studio 2012\Projects\Barcode Scanner using Webcam in VB.NET\Barcode Scanner using Webcam in VB.NET\Form1.vb 16 40 Barcode Scanner using Webcam in VB.NET
Error 1 'Public Event NewFrame(sender As Object, eventArgs As AForge.Video.NewFrameEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\Admin\documents\visual studio 2012\Projects\Barcode Scanner using Webcam in VB.NET\Barcode Scanner using Webcam in VB.NET\Form1.vb 16 9 Barcode Scanner using Webcam in VB.NET
'Code in VB.NET
Private Sub btnStart_Click_1(sender As Object, e As EventArgs) Handles btnStart.Click
videoCaptureDevice = New VideoCaptureDevice(filterInfoCollection(cboCamera.SelectedIndex).MonikerString)
'the line of code below error
videoCaptureDevice.NewFrame = VideoCaptureDevice_NewFrame
videoCaptureDevice.Start()
End Sub
Private Sub VideoCaptureDevice_NewFrame(ByVal sender As Object, ByVal eventArgs As AForge.Video.NewFrameEventArgs)
Dim bitmap As Bitmap = DirectCast(eventArgs.Frame.Clone(), Bitmap)
Dim reader As New BarcodeReader()
Dim result = reader.Decode(bitmap)
If result IsNot Nothing Then
txtBarcode.Invoke(New MethodInvoker(Sub()
txtBarcode.Text = result.ToString()
End Sub))
End If
pictureBox.Image = bitmap
End Sub
'Code in C#
private void btnStart_Click(object sender, EventArgs e)
{
videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[cboCamera.SelectedIndex].MonikerString);
videoCaptureDevice.NewFrame = VideoCaptureDevice_NewFrame;
videoCaptureDevice.Start();
}
private void VideoCaptureDevice_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
BarcodeReader reader = new BarcodeReader();
var result = reader.Decode(bitmap);
if (result != null)
{
txtBarcode.Invoke(new MethodInvoker(delegate()
{
txtBarcode.Text = result.ToString();
}));
}
pictureBox.Image = bitmap;
}
CodePudding user response:
That's not how you register an event hander in VB. This:
videoCaptureDevice.NewFrame = VideoCaptureDevice_NewFrame
should be this:
AddHandler videoCaptureDevice.NewFrame, AddressOf VideoCaptureDevice_NewFrame