How to capture camera with VB.NET

1

Posted on : 13-01-2011 | By : ocx | In : Develop
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Please note: this how-to article refer to software developers and software authors.

This article will show you how to capture video and frame from the camera using the Video Camera ActiveX and VB.NET.

Requirements:

This sample using VB.NET. You can find more samples under the installation program of the component.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
    'Init the control:
    'Must be call before using any
    'functionality of the control.
    'sKey = Your registration key.
    'On trial mode use the "Trial Mode."
    AxcVidCam1.Init ("Trial Mode.")
 
    GetDrivers()
 
    'Or get the drivers without VB collection
    'GetDriversX()

End Sub
 
Private Sub GetDrivers()
 
    'Load the drivers
    Dim cDrivers As VBA.Collection
    Dim cntr As Long
 
    cDrivers = AxcVidCam1.GetDrivers
 
    If cDrivers.Count > 0 Then
 
        For cntr = 1 To cDrivers.Count
            cboDrivers.Items.Add (cDrivers.Item(cntr))
        Next cntr
 
        'Select the first driver
        cboDrivers.SelectedIndex = 0
 
    End If
 
End Sub
 
Private Sub GetDriversX()
 
    'Load the drivers without VB collection
    Dim cntr As Long
    Dim lDriversCount As Long
 
    lDriversCount = AxcVidCam1.GetDriversX
 
    If lDriversCount > 0 Then
 
        For cntr = 1 To lDriversCount
            cboDrivers.Items.Add (AxcVidCam1.GetDriverXVal(cntr))
        Next cntr
 
        'Select the first driver
        cboDrivers.SelectedIndex = 0
 
    End If
 
End Sub
 
Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
 
    'Release the control
    'from the memory:
    AxcVidCam1.DeInit()
End Sub
 
Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
 
    'Connect to the driver
    Call AxcVidCam1.ConnectDriver(cboDrivers.SelectedIndex)
 
End Sub
 
Private Sub cmdSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSource.Click
 
    'Set the source options
    AxcVidCam1.SetSource()
 
End Sub
 
Private Sub cmdFormat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFormat.Click
 
    'Set format options
    AxcVidCam1.SetFormat()
 
End Sub
 
Private Sub cmdLoadPalette_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadPalette.Click
 
    'Load Palette
    AxcVidCam1.PaletteLoad()
 
End Sub
 
Private Sub cmdSavePalette_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSavePalette.Click
 
    'Save Palette
    AxcVidCam1.PaletteSave()
 
End Sub
 
Private Sub cmdDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisplay.Click
 
    'Set display options
    AxcVidCam1.SetDisplay()
 
End Sub
 
Private Sub cmdCompression_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompression.Click
 
    'Set video compression
    AxcVidCam1.SetCompression()
 
End Sub
 
Private Sub cmdSetCaptureFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSetCaptureFile.Click
 
    'Set the capture video file
    AxcVidCam1.SetCapFile ("C:\camera_capture.avi")
 
End Sub
 
Private Sub cmdAudioFormat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAudioFormat.Click
 
    'Set audio compression
    AxcVidCam1.SetAudioFormatDlg()
 
End Sub
 
Private Sub cmdCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCapture.Click
 
    'Set the movie file
    AxcVidCam1.SetCapFile ("C:\camera_capture.avi")
 
    'Start capture
    AxcVidCam1.Capture(15, False, 30, True, True, True, True, True, -1)
 
End Sub
 
Private Sub cmdFrame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFrame.Click
 
    'Capture frame to bmp
    AxcVidCam1.SaveSingleFrame ("C:\CamCapture.bmp")
 
End Sub
 
Private Sub AxcVidCam1_Error(ByVal sender As Object, ByVal e As AxVIDEO_CAMERA_ACTIVEX.__cVidCam_ErrorEvent) Handles AxcVidCam1.Error
 
    'Display error message
    MsgBox ("Error: " & e.sErrMessage & "(" & e.lErrNumber & ")")
 
End Sub

ocx

Hello All! I'm the author of ocx-active.com. My website contains many activex components for software developers and software authors. I've decide to put at the 3howto.com some samples of using the components of my website. Enjoy it :)

Comments (1)

hello. it tried this code in vb10. it works however, the preview window turns black when the preview button is pressed. what could possibly be the problem and how can i fix it?? thanks

Post a comment

You must be logged in to post a comment.