taking picture with the webcam
Posted: Fri Nov 27, 2009 9:42 pm
Hello:
is it possible to take a picture with the webcam? and how?
thanks
is it possible to take a picture with the webcam? and how?
thanks
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
#WM_CAP_START = #WM_USER
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11
#WM_CAP_DRIVER_GET_CAPS = #WM_CAP_START + 14
#WM_CAP_EDIT_COPY = #WM_CAP_START + 30
#WM_CAP_SET_PREVIEW = #WM_CAP_START + 50
#WM_CAP_SET_PREVIEWRATE = #WM_CAP_START + 52
#WM_CAP_STOP = #WM_CAP_START + 68
#WM_CAP_SET_SCALE = #WM_CAP_START + 53
#WM_CAP_DLG_VIDEOFORMAT = #WM_CAP_START + 41
#WM_CAP_DLG_VIDEOSOURCE = #WM_CAP_START + 42
#WM_CAP_DLG_VIDEODISPLAY = #WM_CAP_START + 43
#WM_CAP_GET_VIDEOFORMAT = #WM_CAP_START + 44
#WM_CAP_SET_VIDEOFORMAT = #WM_CAP_START + 45
#WM_CAP_DLG_VIDEOCOMPRESSION = #WM_CAP_START + 46
Import "avicap32.lib"
CapCreateCaptureWindow.i(name.s, style.i, x.i, y.i, width.i, height.i, hWndParent.i, nId.i) As "_capCreateCaptureWindowA@32"
CapGetDriverDescription.i(index.i, name.i, cbName.i, ver.i, cbVer.i) As "_capGetDriverDescriptionA@20"
EndImport
;======if the compiler can't find the lib use this and call close library at the end of your code
; Prototype.i ProtCapCreateCaptureWindow(name.s, style.i, x.i, y.i, width.i, height.i, hWndParent.i, nId.i)
; Prototype.i ProtCapGetDriverDescription(index.i, name.i, cbName.i, ver.i, cbVer.i)
;
; If OpenLibrary(0, "avicap32.dll")
; Global CapCreateCaptureWindow.ProtCapCreateCaptureWindow = GetFunction(0, "capCreateCaptureWindowA")
; Global CapGetDriverDescription.ProtCapGetDriverDescription = GetFunction(0, "capGetDriverDescriptionA")
; EndIf
Procedure CapImage()
Static sct
sfile.s = SaveFileRequester("Save","c:\cap" + Str(sct) + ".bmp","*.bmp",1)
image = GetClipboardImage(#PB_Any,32)
If image
SaveImage(image,sfile)
sct+1
EndIf
EndProcedure
mwind = OpenWindow(#PB_Any,0,0,320,270,"WebCam",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
If mwind
Butcap = ButtonGadget(#PB_Any,5,245,60,20,"Capture")
hCapWnd= CapCreateCaptureWindow("CapWindow", #WS_CHILD | #WS_VISIBLE,0,0,320,240,WindowID(mwind),0)
SendMessage_(hCapWnd, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hCapWnd, #WM_CAP_SET_PREVIEW, 1, 0)
SendMessage_(hCapWnd, #WM_CAP_SET_PREVIEWRATE, 10, 0)
SendMessage_(hCapWnd, #WM_CAP_SET_SCALE,1,0)
SendMessage_(hCapWnd, #WM_CAP_DLG_VIDEOFORMAT, 0, 0)
Repeat
ev = WaitWindowEvent()
If ev = #PB_Event_Gadget
evg = EventGadget()
If evg = Butcap
PostMessage_(hCapWnd,#WM_CAP_EDIT_COPY,0,0)
CapImage()
EndIf
EndIf
Until ev = #PB_Event_CloseWindow
SendMessage_(hCapWnd, #WM_CAP_STOP, 0, 0)
SendMessage_(hCapWnd,#WM_CAP_DRIVER_DISCONNECT,0,0)
DestroyWindow_(hCapWnd)
EndIf