Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - Salvare immagini da webcam
Forum - Visual Basic 6 - Salvare immagini da webcam

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
ddemarch (Normal User)
Rookie


Messaggi: 29
Iscritto: 17/08/2009

Segnala al moderatore
Postato alle 13:41
Mercoledì, 26/08/2009
Salve,
ho utilizzato il seguente codice per acquisire immagini da webcam e vedo il live

in un modulo:
Codice sorgente - presumibilmente VB.NET

  1. Global Const ws_child As Long = &H40000000
  2. Global Const ws_visible As Long = &H10000000
  3. Global Const WM_USER = 1024
  4. Global Const wm_cap_driver_connect = WM_USER + 10
  5. Global Const wm_cap_set_preview = WM_USER + 50
  6. Global Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
  7. Global Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11
  8. Global Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_USER + 41
  9. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  10. Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long



Nel form:
                
Codice sorgente - presumibilmente VB.NET

  1. Private Sub Form_Load()
  2.  
  3. Dim hwdc As Long
  4. Dim startcap As Boolean
  5.  
  6. Dim temp As Long
  7. hwdc = capCreateCaptureWindow("visione", ws_child Or ws_visible, 0, 0, 320, 240, Picture1.hWnd, 0)
  8. If (hwdc <> 0) Then
  9. temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
  10. temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
  11. temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 100)
  12. 'temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
  13. startcap = True
  14. Else
  15. MsgBox ("No Webcam found")
  16. End If
  17.  
  18. End Sub


Ora vorrei salvare dei fotogrammi tramite un button, come potrei farlo?
Grazie..

Ultima modifica effettuata da ddemarch il 26/08/2009 alle 13:42
PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 14:49
Mercoledì, 26/08/2009
Devi usare questo codice che metterai nel button

Codice sorgente - presumibilmente Plain Text

  1. SendMessage hwdc, WM_CAP_EDIT_COPY, 0, 0
  2. Picture1.Picture = Clipboard.GetData
  3. SavePicture Picture1.Image, "percorso\immagine.bmp"


PM Quote
Avatar
ddemarch (Normal User)
Rookie


Messaggi: 29
Iscritto: 17/08/2009

Segnala al moderatore
Postato alle 14:54
Mercoledì, 26/08/2009
Grazie GrG, però c'è un problemino: l'immagine viene salvata ma vedo solo una bmp del colore dello sfondo della pictureBox..
Questa:
http://img41.imageshack.us/img41/8711/fotoary.png
oppure senza il disegnetto in alto a sinistra.
Cosa potrebbe essere?

Ultima modifica effettuata da ddemarch il 26/08/2009 alle 15:38
PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 16:53
Mercoledì, 26/08/2009
Mi ero dimenticato di dirti di aggiungere queste dichiarazioni

Global Const WM_CAP As Integer = &H400
Global Const WM_CAP_EDIT_COPY As Long = WM_CAP + 30

nel modulo, dovrebbe andare :)

Ultima modifica effettuata da GrG il 26/08/2009 alle 16:54
PM Quote
Avatar
ddemarch (Normal User)
Rookie


Messaggi: 29
Iscritto: 17/08/2009

Segnala al moderatore
Postato alle 16:59
Mercoledì, 26/08/2009
Ho aggiunto ma nn funzia ancora..
L'immagine acquisita é sempre del colore dello sfondo..
:d

Ultima modifica effettuata da ddemarch il 26/08/2009 alle 17:06
PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 18:29
Mercoledì, 26/08/2009
mm.. ok mi sono messo a provare, se vedi nella form load c'è questa stringa

temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 100)

sostituisci l'ultimo valore (cioè 100) con 0

ossia

temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)

vedrai che funziona ;)

PM Quote
Avatar
ddemarch (Normal User)
Rookie


Messaggi: 29
Iscritto: 17/08/2009

Segnala al moderatore
Postato alle 8:13
Giovedì, 27/08/2009
Eh GrG mi dispiace ma nn mi funzia ancora.. :asd:
Ti posto tutto il codice che ho, magari provando ho modificato dei parametri che non dovevo..

Modulo:
Codice sorgente - presumibilmente VB.NET

  1. Global Const ws_child As Long = &H40000000
  2. Global Const ws_visible As Long = &H10000000
  3. Global Const WM_USER = 1024
  4. Global Const wm_cap_driver_connect = WM_USER + 10
  5. Global Const wm_cap_set_preview = WM_USER + 50
  6. Global Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
  7. Global Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11
  8. Global Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_USER + 41
  9. Global Const WM_CAP As Integer = &H400
  10. Global Const WM_CAP_EDIT_COPY As Long = WM_CAP + 30
  11.  
  12. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  13. Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long



Form:
Codice sorgente - presumibilmente VB.NET

  1. Private Sub Form_Load()
  2.  
  3. Dim hwdc As Long
  4. Dim startcap As Boolean
  5.  
  6. Dim temp As Long
  7. hwdc = capCreateCaptureWindow("visione", ws_child Or ws_visible, 0, 0, 320, 240, Picture1.hWnd, 0)
  8. If (hwdc <> 0) Then
  9. temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
  10. temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
  11. temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
  12. 'temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
  13. startcap = True
  14. Else
  15. MsgBox ("No Webcam found")
  16. End If
  17.  
  18. End Sub
  19.  
  20.  
  21. Private Sub salva_Click()
  22. SendMessage hwdc, WM_CAP_EDIT_COPY, 0, 0
  23. Picture1.Picture = Clipboard.GetData
  24. SavePicture Picture1.Image, "C:\Documents and Settings\...\immagine.bmp"
  25. End Sub



L'immagine salvata ha sempre il colore dello sfondo, però vedo che viene sovrascritta cioe quando salvo crea una nuova foto e nn rimane sempre la stessa..

Grazie

Ultima modifica effettuata da ddemarch il 27/08/2009 alle 8:37
PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 10:33
Giovedì, 27/08/2009
devi spostare la dichiarazione della variabile hwdc fuori dalla sub form_load quindi metterla "in generale"

Ultima modifica effettuata da GrG il 27/08/2009 alle 10:34
PM Quote
Avatar
ddemarch (Normal User)
Rookie


Messaggi: 29
Iscritto: 17/08/2009

Segnala al moderatore
Postato alle 10:39
Giovedì, 27/08/2009
Funziona!! Ho capito l'errore.. :rotfl:
Grazie mille per il tuo aiuto GrG!!! :k:

PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo