从摄像头视频捕获图像(aforge)

时间:2019-08-11 20:27:56

标签: vb.net

来自this link vb项目,我想截取屏幕截图并将其另存为图像,但是我失败了

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If (Not System.IO.Directory.Exists("C:\Users\" + Environment.UserName.ToString + "\AppData\SystemInfo\Webcam")) Then
        My.Computer.FileSystem.CreateDirectory("C:\Users\" + Environment.UserName.ToString + "\AppData\SystemInfo\Webcam")
    End If

    ' If My.Computer.Network.IsAvailable Then
    Dim screenSize As Size = New Size(VideoSourcePlayer1.Width, VideoSourcePlayer1.Height)
    Dim screenGrab As New Bitmap(VideoSourcePlayer1.Width, VideoSourcePlayer1.Height)

    Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
    ' g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenSize)
    g.Dispose()
    ' If (System.IO.Directory.Exists("C:\Users\" + Environment.UserName.ToString + "\AppData\SystemInfo\Images")) Then
    screenGrab.Save("C:\Users\" + Environment.UserName.ToString + "\AppData\SystemInfo\Webcam" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    ' screenGrab.Save("testNyox.jpg")
    '  End If
    PictureBox1.Image = screenGrab
End Sub

但是它捕获实时窗口如何从网络摄像头使用中捕获图像 Aforge.net?以及如何从this project捕获图像并将其保存到我的计算机中

1 个答案:

答案 0 :(得分:1)

解决方案实际上是在您提供的link中给出的。 Aforge VideoSourcePlayer控件具有一个事件,只要框架准备就绪,就会触发该事件,并将该帧图像传递给事件处理程序。因此,只需创建一个Snap按钮,单击该按钮即可设置一个Boolean变量,该变量指示是时候进行快照了。在事件处理程序中,检查变量的状态,以确定是否保存下一帧图像。

Private Sub SnapButton_Click(sender As Object, e As EventArgs) Handles SnapButton.Click
    _takeSnapshot = True
End Sub

Private _takeSnapshot As Boolean

Private Sub VideoSourcePlayer1_NewFrame(sender As Object, ByRef image As Bitmap) Handles VideoSourcePlayer1.NewFrame
    If _takeSnapshot Then

        ' Put your image saving / processing code here.

        _takeSnapshot = False
    End If
End Sub