TWebcam

Source: source/classes/twebcam.prg

Hierarchy: TWebcamTControl

TWebcam provides live webcam preview and capture functionality using the Video for Windows (VFW) API. It is a visual control that displays the camera feed within a FiveWin window and supports snapshot capture, video format dialogs, and video source configuration.

WEBCAM Command

@ nRow, nCol WEBCAM oCam OF oWnd SIZE nW, nH INIT lInit

Key DATA Members

DATATypeDefaultDescription
hWebcamNumericHandle to the VFW capture window
cNameCharacterWebcam driver description
cVersionCharacterWebcam driver version string
nRateRefreshNumeric66Preview refresh rate in milliseconds
isScaleLogical.T.Scale preview to control size (640x480 when disabled)
isConnectedLogical.F.Whether preview is currently active

Methods

MethodDescription
New( oWnd, nTop, nLeft, nWidth, nHeight, lInit, lAdjust, nRate, bError )Constructor. Creates the VFW capture window and optionally starts preview.
Initialize()Connect the webcam driver and start the live preview.
Finalize()Disconnect the webcam driver and stop the preview.
SaveFile( cFileName )Capture the current frame to a BMP file. Defaults to a timestamp-based filename.
VideoControl()Open the video source property dialog (brightness, contrast, etc.).
VideoFormat()Open the video format dialog (resolution, color depth).
StartCapture( cFile )Begin streaming capture to a video file.
StopCapture()Stop any ongoing video capture.
GetWidth()Return the current preview image width in pixels.
GetHeight()Return the current preview image height in pixels.
SetRate( nRate )Set the preview refresh rate in milliseconds.

Example: Live Preview with Capture

#include "FiveWin.ch"

function Main()

   local oWnd, oCam, lInit := .T.

   DEFINE WINDOW oWnd TITLE "Webcam Capture" ;
      SIZE 800, 600

   @ 10, 10 WEBCAM oCam OF oWnd SIZE 640, 480 INIT lInit

   @ 500, 10 BUTTON "&Snapshot" SIZE 60, 25 ;
      ACTION oCam:SaveFile( "snap.bmp" )

   @ 500, 80 BUTTON "&Format" SIZE 60, 25 ;
      ACTION oCam:VideoFormat()

   @ 500, 150 BUTTON "&Controls" SIZE 60, 25 ;
      ACTION oCam:VideoControl()

   @ 500, 220 BUTTON "&Close" SIZE 60, 25 ;
      ACTION oWnd:End()

   ACTIVATE WINDOW oWnd ;
      ON INIT oCam:Initialize() ;
      VALID ( oCam:Finalize(), .T. )

return nil

Notes

See Also