Visual Basic Connect to Webcam and Save Picture to File

强颜欢笑 提交于 2021-01-29 06:22:31

问题


Most simply put, I want to connect to a built in web cam in my computer using visual basic, take a single picture, and save that in a file. I have spent about an hour or so looking for a reasonable way to do this, and have found a few suggestions. Unfortunately many the methods that I have tried seem unnecessarily complicated and I have yet to see one of them work on my computer. For example, I have tried using the icam class referenced in several places, where this code

Public Class Form1

    Private Sub Snap()
        Dim Webcam As iCam = New iCam
        Webcam.initCam(PictureBox1.Handle.ToInt32)
        Application.DoEvents()
        If Webcam.iRunning Then
            PictureBox2.Image = Webcam.copyFrame(PictureBox1, New RectangleF(0, 0, PictureBox1.Width, PictureBox1.Height))
        End If
        Webcam.closeCam()
        Webcam = Nothing
    End Sub

    Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click

    End Sub
End Class

Threw this error:

An unhandled exception of type 'System.InvalidOperationException' occurred in facerecognition.exe
Additional information: An error occurred creating the form. See Exception.InnerException for details.  The error is: Failed to initialize because CategoryName is missing.

While with some work I could probably get the class functioning as it is meant to, the issue remains that there is really no simple and clean solution to this that I know of. Does anyone have a better idea of how to do this?

来源:https://stackoverflow.com/questions/30086084/visual-basic-connect-to-webcam-and-save-picture-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!