VB上的Auto Trigger网络摄像头QR扫描仪

时间:2018-05-02 11:19:50

标签: vb.net qr-code webcam

我有一个使用Visual Basic的简单Windows窗体程序,使用网络摄像头扫描QR码。但是我的程序在扫描时使用两个按钮,启动按钮以启动网络摄像头并检测按钮以扫描QR。我的问题是,如何将两个按钮合二为一,所以当我启动网络摄像头时,它会自动扫描前面的二维码。这是我的开始和检测按钮。

   Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles Button1.Click
    StartWebcam()
    TextBox1.Clear()
End Sub

    Private Sub ButtonDetect_Click(sender As Object, e As EventArgs) Handles Button3.Click
    'Scans the received image
    Try
        StopWebcam()
        Reader = New QRCodeDecoder
        TextBox1.Text = Reader.decode(New Data.QRCodeBitmapImage(PictureBox1.Image))
        MsgBox("QR code is detected!")
    Catch ex As Exception
        StartWebcam()
    End Try
End Sub

2 个答案:

答案 0 :(得分:0)

可能是一个很长的镜头,但你可以尝试这样组合(我假设主按钮将是Button1

Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles Button1.Click
    StartWebcam()
    TextBox1.Clear()
    Try
        StopWebcam()
        Reader = New QRCodeDecoder
        TextBox1.Text = Reader.decode(New Data.QRCodeBitmapImage(PictureBox1.Image))
        MsgBox("QR code is detected!")
    Catch ex As Exception
        StartWebcam()
    End Try
End Sub

希望我帮助或至少给了你一些想法:)

答案 1 :(得分:0)

如果我错了,请纠正我:你想执行/调用StartWebcam方法,当执行完成时,你想要调用其余的代码吗?如果是,Async / Await是您的最佳选择:

 ''Firstly,make your StartWebcam method an Async method :

  Async Sub StartWebcam()
  '''codes here
  End sub

  '''Now call the method from your button :    
  TextBox1.Clear()
  Await StartWebcam()

  '''now the other codes that will be executed after StartWebcam is done executing 

   Try
    StopWebcam()
    Reader = New QRCodeDecoder
    TextBox1.Text = Reader.decode(New Data.QRCodeBitmapImage(PictureBox1.Image))
    MsgBox("QR code is detected!")
Catch ex As Exception
    StartWebcam()
End Try

希望这会有所帮助:)