This sample will show you how to use the Camera Capture ActiveX from VB dot net. This ActiveX component is an OCX and it allows you to use any camera connected to your PC. You can display the camera, capture frame as an image, capture frames as a video, and more.
Requirements:
- Visual Basic 2008/2010
- Camera Capture ActiveX | Download
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 | Option Strict Off Option Explicit On Friend Class frmMain Inherits System.Windows.Forms.Form Private Sub cCam1_Error(ByVal eventSender As System.Object, ByVal eventArgs As AxCamera_Capture_ActiveX.__cCam_ErrorEvent) Handles cCam1.Error 'Display error message MsgBox("Error: " & eventArgs.sErrMessage & "(" & eventArgs.lErrNumber & ")") End Sub Private Sub cmdCompression_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCompression.Click 'Set video compression cCam1.SetCompression() End Sub Private Sub cmdAudioFormat_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAudioFormat.Click 'Set audio compression cCam1.SetAudioFormatDlg() End Sub Private Sub cmdCapture_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCapture.Click 'Set the movie file cCam1.SetCapFile("C:\camera_capture.avi") 'Start capture 'UPGRADE_NOTE: Capture was upgraded to CtlCapture. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"' cCam1.Capture(15, False, 30, True, True, True, True, True, -1) End Sub Private Sub cmdConnect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdConnect.Click 'Connect to the driver Call cCam1.ConnectDriver(cboDrivers.SelectedIndex) 'Disable the logo: picLogo.Visible = False End Sub Private Sub cmdDisplay_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDisplay.Click 'Set display options cCam1.SetDisplay() End Sub Private Sub cmdFormat_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFormat.Click 'Set format options cCam1.SetFormat() End Sub Private Sub cmdFrame_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFrame.Click 'Capture frame to bmp cCam1.SaveSingleFrame("C:\CamCapture.bmp") End Sub Private Sub cmdLoadPalette_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLoadPalette.Click 'Load Palette cCam1.PaletteLoad() End Sub Private Sub cmdSavePalette_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSavePalette.Click 'Save Palette cCam1.PaletteSave() End Sub Private Sub cmdSetCaptureFile_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSetCaptureFile.Click 'Set the capture video file cCam1.SetCapFile("C:\camera_capture.avi") End Sub Private Sub cmdSource_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSource.Click 'Set the source options cCam1.SetSource() End Sub Private Sub frmMain_Load(ByVal eventSender As System.Object, ByVal eventArgs 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." cCam1.Init("Trial Mode.") 'Load the drivers Dim cntr As Integer Dim lDeviceCntr As Integer lDeviceCntr = cCam1.GetDriversX If lDeviceCntr > 0 Then For cntr = 1 To lDeviceCntr cboDrivers.Items.Add(cCam1.GetDriverXVal(cntr)) Next cntr 'Select the first driver cboDrivers.SelectedIndex = 0 End If End Sub Private Sub frmMain_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed 'Release the control 'from the memory: cCam1.DeInit() End Sub End Class |
Links:
- Visual Basic 2008/2010
- Camera Capture ActiveX | Download
read the original story ...