
Les codes fonctionnels pour webcam ne sont pas légions,
Voilà donc un code trouvé sur le fofo anglais que j'ai bidouillé pour afficher l'image dans un canvasgadget()
ça marche plutôt bien

Escapi DLL : http://stock.ldvmultimedia.com/escapi.7z
Le .PBI : escapi.pbi
Code : Tout sélectionner
;/* Extremely Simple Capture API */
Structure SimpleCapParams
*mTargetBuf.l ; Must be at least mWidth * mHeight * SizeOf(int) of size!
mWidth.l
mHeight.l
EndStructure
;/* Return the number of capture devices found */
PrototypeC countCaptureDevicesProc()
; /* initCapture tries To open the video capture device.
; * Returns 0 on failure, 1 on success.
; * Note: Capture parameter values must Not change While capture device
; * is in use (i.e. between initCapture And deinitCapture).
; * Do *Not* free the target buffer, Or change its pointer!
; */
PrototypeC initCaptureProc(deviceno, *aParams.SimpleCapParams)
;/* deinitCapture closes the video capture device. */
PrototypeC deinitCaptureProc(deviceno)
;/* doCapture requests video frame To be captured. */
PrototypeC doCaptureProc(deviceno)
;/* isCaptureDone returns 1 when the requested frame has been captured.*/
PrototypeC isCaptureDoneProc(deviceno)
;/* Get the user-friendly name of a capture device. */
PrototypeC getCaptureDeviceNameProc(deviceno, *namebuffer, bufferlength)
;/* Returns the ESCAPI DLL version. 0x200 For 2.0 */
PrototypeC ESCAPIDLLVersionProc()
; marked as "internal" in the example
PrototypeC initCOMProc()
Global countCaptureDevices.countCaptureDevicesProc
Global initCapture.initCaptureProc
Global deinitCapture.deinitCaptureProc
Global doCapture.doCaptureProc
Global isCaptureDone.isCaptureDoneProc
Global getCaptureDeviceName.getCaptureDeviceNameProc
Global ESCAPIDLLVersion.ESCAPIDLLVersionProc
Procedure setupESCAPI()
; load library
capdll = OpenLibrary(#PB_Any, "escapi.dll")
If capdll = 0
ProcedureReturn 0
EndIf
;/* Fetch function entry points */
countCaptureDevices = GetFunction(capdll, "countCaptureDevices")
initCapture = GetFunction(capdll, "initCapture")
deinitCapture = GetFunction(capdll, "deinitCapture")
doCapture = GetFunction(capdll, "doCapture")
isCaptureDone = GetFunction(capdll, "isCaptureDone")
initCOM.initCOMProc = GetFunction(capdll, "initCOM")
getCaptureDeviceName = GetFunction(capdll, "getCaptureDeviceName")
ESCAPIDLLVersion = GetFunction(capdll, "ESCAPIDLLVersion")
If countCaptureDevices = 0 Or initCapture = 0 Or deinitCapture = 0 Or doCapture = 0 Or isCaptureDone = 0 Or initCOM = 0 Or getCaptureDeviceName = 0 Or ESCAPIDLLVersion = 0
ProcedureReturn 0
EndIf
;/* Verify DLL version */
If ESCAPIDLLVersion() < $200
ProcedureReturn 0
EndIf
;/* Initialize COM.. */
initCOM();
; returns number of devices found
ProcedureReturn countCaptureDevices()
EndProcedure
; IDE Options = PureBasic 4.50 Beta 3 (Windows - x86)
; CursorPosition = 3
; FirstLine = 1
Le Code pour tester :
Code : Tout sélectionner
IncludeFile "escapi.pbi"
#WIDTH = 320 ;1280
#HEIGHT = 240 ;#WIDTH * 0.5625 ;16:9 ASPECT RATIO -- YOU MAY ADJUST TO SUIT
#WIDTHM1 = #WIDTH - 1
#HEIGHTM1 = #HEIGHT - 1
pixCount = (#WIDTH * #HEIGHT) - 2
device = 0
count = setupESCAPI()
; Debug "Init: " + Str(count)
If count = 0
MessageRequester("Error", "Unable to initialize ESCAPI.")
End
EndIf
name$ = Space(255)
getCaptureDeviceName(device, @name$, 255)
; Debug "Name: " + name$
bufSize = #WIDTH * #HEIGHT * 4
scp.SimpleCapParams
scp\mWidth = #WIDTH
scp\mHeight = #HEIGHT
scp\mTargetBuf = AllocateMemory(bufSize)
*buf = scp\mTargetBuf
If initCapture(device, @scp)
; Debug "Cap init successful."
Image = CreateImage(0, #WIDTH, #HEIGHT, 24)
OpenWindow(0, 50, 50, #WIDTH, #HEIGHT, name$, #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, #WIDTH, #HEIGHT)
If StartDrawing(CanvasOutput(0))
DrawImage(ImageID(0), 0, 0, #WIDTH, #HEIGHT)
StopDrawing()
EndIf
offset = 0
Quit = #False
Repeat
doCapture(device)
While isCaptureDone(device) = #False
If WaitWindowEvent(1) = #PB_Event_CloseWindow
Quit = #True
Break
EndIf
Wend
offset = 0
StartDrawing(CanvasOutput(0))
*writeBuffer = DrawingBuffer()
pitch = DrawingBufferPitch()
StopDrawing()
;NEEDS PIXEL-BY-PIXEL READING AND WRITING
For Y = 0 To #HEIGHTM1
hm1 = *writeBuffer + ((#HEIGHTM1 - Y) * pitch)
For X = 0 To #WIDTHM1
PokeL(hm1 + X * 3, PeekL(*buf + offset))
offset + 4
Next
Next
SetGadgetState(0, ImageID(0))
Until Quit
deinitCapture(device)
FreeImage(0)
FreeMemory(scp\mTargetBuf)
CloseWindow(0)
Else
Debug "Init capture failed."
EndIf
End