0

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?

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
trevorKirkby
  • 1,886
  • 20
  • 47
  • 1
    A quick search yielded this... https://anoriginalidea.wordpress.com/2010/10/04/capturing-a-still-image-from-a-webcam-in-net/ – Trevor May 07 '15 at 02:25
  • Looks like a modified iCam class... – trevorKirkby May 08 '15 at 18:59
  • Actually never mind it is built similarly but I don't think it is based off iCam – trevorKirkby May 08 '15 at 19:02
  • Is there any particular reason why both iCam and this other class both open eight random windows when I open the program? – trevorKirkby May 08 '15 at 19:30
  • No it's not, I have used this before and it works just fine for me... – Trevor May 08 '15 at 19:31
  • I don't recall that ever happening to me, I know it opens up a window to select a cam if I remember correctly. – Trevor May 08 '15 at 19:31
  • It opened a selection window too. Just eight others that looked like some kind of output setup. – trevorKirkby May 08 '15 at 19:32
  • I also had to make some modifications to it as well, but it's been awhile ago since I have done anything with it... – Trevor May 08 '15 at 19:32
  • Hm. Well I will look into how to best use this class and see if it works. If anyone has suggestions I am still open to them but for now this looks like the best option. – trevorKirkby May 08 '15 at 19:33
  • Maybe this is just because I am used to the python way of doing things but it seems like the way visual basic is built makes it very difficult to find a simple solution to something like this. – trevorKirkby May 08 '15 at 19:34
  • 1
    Did it not work without the modifications? – trevorKirkby May 08 '15 at 19:35
  • Huh. The windows (apart from the camera selection one) didn't open this time (and I made no changes to the program). It still hasn't resulted in a jpg file, which I am pretty sure this ought to result in, however. – trevorKirkby May 08 '15 at 19:37

0 Answers0