| 关键词: lwndC PARAMS Capture cap driver picture lpszName Caps Window False |
操作摄像头我想主要有以下几点。启动摄像头;将摄像头的视频流转为图片或视频文件保存;一些设置。 启动摄像头 包括创建捕捉窗口,连接硬件设备,显示图像以及一些基本设置。view plaincopy to clipboardprint? Dim lpszName As String * 100 Dim lpszVer As String * 100 Dim Caps As CAPDRIVERCAPS '//Create Capture Window capGetDriverDescriptionA 0, lpszName, 100, lpszVer, 100 '// Retrieves driver info lwndC = capCreateCaptureWindowA(lpszName, WS_CAPTION Or WS_THICKFRAME Or WS_VISIBLE Or WS_CHILD, 0, 0, 160, 120, Me.hWnd, 0) '// Set title of window to name of driver SetWindowText lwndC, lpszName '// Set the video stream callback function 'capSetCallbackOnStatus lwndC, AddressOf MyStatusCallback 'capSetCallbackOnError lwndC, AddressOf MyErrorCallback '// Connect the capture window to the driver If capDriverConnect(lwndC, 0) Then '///// '// Only do the following if the connect was successful. '// if it fails, the error will be reported in the call '// back function. '///// '// Get the capabilities of the capture driver capDriverGetCaps lwndC, VarPtr(Caps), Len(Caps) '// If the capture driver does not support a dialog, grey it out '// in the menu bar. If Caps.fHasDlgVideoSource = 0 Then mnuSource.Enabled = False If Caps.fHasDlgVideoFormat = 0 Then mnuFormat.Enabled = False If Caps.fHasDlgVideoDisplay = 0 Then mnuDisplay.Enabled = False '// Turn Scale on capPreviewScale lwndC, True '// Set the preview rate in milliseconds capPreviewRate lwndC, 66 '// Start previewing the image from the camera capPreview lwndC, True '// Resize the capture window to show the whole image ResizeCaptureWindow lwndC End If Dim lpszName As String * 100 Dim lpszVer As String * 100 Dim Caps As CAPDRIVERCAPS '//Create Capture Window capGetDriverDescriptionA 0, lpszName, 100, lpszVer, 100 '// Retrieves driver info lwndC = capCreateCaptureWindowA(lpszName, WS_CAPTION Or WS_THICKFRAME Or WS_VISIBLE Or WS_CHILD, 0, 0, 160, 120, Me.hWnd, 0) '// Set title of window to name of driver SetWindowText lwndC, lpszName '// Set the video stream callback function 'capSetCallbackOnStatus lwndC, AddressOf MyStatusCallback 'capSetCallbackOnError lwndC, AddressOf MyErrorCallback '// Connect the cap ture window to the driver If capDriverConnect(lwndC, 0) Then '///// '// Only do the following if the connect was successful. '// if it fails, the error will be reported in the call '// back function. '///// '// Get the capabilities of the capture driver capDriverGetCaps lwndC, VarPtr(Caps), Len(Caps) '// If the capture driver does not support a dialog, grey it out '// in the menu bar. If Caps.fHasDlgVideoSource = 0 Then mnuSource.Enabled = False If Caps.fHasDlgVideoFormat = 0 Then mnuFormat.Enabled = False If Caps.fHasDlgVideoDisplay = 0 Then mnuDisplay.Enabled = False '// Turn Scale on capPreviewScale lwndC, True '// Set the preview rate in milliseconds capPreviewRate lwndC, 66 '// Start previewing the image from the camera capPreview lwndC, True '// Resize the capture window to show the whole image ResizeCaptureWindow lwndC End If 将视频流转为图片或文件保存 关于保存为图片好像没有什么直接方法,我用的是在窗体中加入了一个picture控件来搞定的。 view plaincopy to clipboardprint? SendMessage(lwnd, WM_CAP_EDIT_COPY, 0, 0) Picture1.Picture = Clipboard.GetData SavePicture Picture1.Picture, "c:\test.webp" SendMessage(lwnd, WM_CAP_EDIT_COPY, 0, 0) Picture1.Picture = Clipboard.GetData SavePicture Picture1.Picture, "c:\test.webp" 保存到视频文件 view plaincopy to clipboardprint? Dim sFileName As String Dim CAP_PARAMS As CAPTUREPARMS capCaptureGetSetup lwndC, VarPtr(CAP_PARAMS), Len(CAP_PARAMS) CAP_PARAMS.dwRequestMicroSecPerFrame = (1 * (10 ^ 6)) / 30 ' 30 Frames per second CAP_PARAMS.fMakeUserHitOKToCapture = True CAP_PARAMS.fCaptureAudio = False capCaptureSetSetup lwndC, VarPtr(CAP_PARAMS), Len(CAP_PARAMS) sFileName = "C:\myvideo.avi" capCaptureSequence lwndC ' Start Capturing! capFileSaveAs lwndC, sFileName ' Copy video from swap file into a real file. Dim sFileName As String Dim CAP_PARAMS As CAPTUREPARMS capCaptureGetSetup lwndC, VarPtr(CAP_PARAMS), Len(CAP_PARAMS) CAP_PARAMS.dwRequestMicroSecPerFrame = (1 * (10 ^ 6)) / 30 ' 30 Frames per second CAP_PARAMS.fMakeUserHitOKToCapture = True CAP_PARAMS.fCaptureAudio = False capCaptureSetSetup lwndC, VarPtr(CAP_PARAMS), Len(CAP_PARAMS) |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|