Postada em 22/05/2008 18:33 hs
ola pessoal, meu problema é o seguinte. preciso capturar a imagem da webcam e salvar em um arquivo. peguei o seguinte codigo aqui no forum:
Public Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
Public mCapHwnd As Long
Public Const CONNECT As Long = 1034 Public Const DISCONNECT As Long = 1035 Public Const GET_FRAME As Long = 1084 Public Const COPY As Long = 1054
Private Sub cmdStart_Click() cmdStart.Enabled = False cmdStop.Enabled = True 'Setup a capture window (You can replace "WebcamCapture" with watever you want) mCapHwnd = capCreateCaptureWindow("WebcamCapture", 0, 0, 0, 320, 240, Me.hwnd, 0) 'Connect to capture device DoEvents: SendMessage mCapHwnd, CONNECT, 0, 0 tmrMain.Enabled = True End Sub
Private Sub cmdStop_Click() cmdStart.Enabled = True cmdStop.Enabled = False tmrMain.Enabled = False 'Make sure to disconnect from capture source!!! DoEvents: SendMessage mCapHwnd, DISCONNECT, 0, 0 End Sub
Private Sub Command1_Click() Dim strNew As String
CommonDialog1.CancelError = True CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt CommonDialog1.Filter = "Fotos (*.bmp)|*.bmp" CommonDialog1.FilterIndex = 2 CommonDialog1.ShowSave strNew = CommonDialog1.FileName
SavePicture img.Picture, strNew
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If cmdStop.Enabled = False Then
'Make sure to disconnect from capture source - if it is connected upon termination the program can become unstable DoEvents: SendMessage mCapHwnd, DISCONNECT, 0, 0 End If End Sub
Private Sub tmrMain_Timer() On Error Resume Next 'Get Current Frame SendMessage mCapHwnd, GET_FRAME, 0, 0 'Copy Current Frame to ClipBoard SendMessage mCapHwnd, COPY, 0, 0 'Put ClipBoard's Data to picOutput img.Picture = Clipboard.GetData 'Clear ClipBoard Clipboard.Clear End Sub
ele funciona perfeitamente, eu só queria q ao inves de salvar via common dialog, ele salvasse automaticamente em "c:" com o nome q eu definisse , q no caso seria a identificação do cliente.
tentei substituir o botão salvar (onde tem o comon dialog) por savepicture a.bmp "c:" mas nao deu certo.
O q deve fazer ?
Obrigado
Marcus
|