I present you the software that allows manage your Webcam with Delphi.
First you have to install the software on your system "Microsoft Video for Windows SDK" that contains the library avicap32.dll.
Among the functions contained use "capCreateCaptureWindowA" to initialize the driver and image capture.
After handling the capture window will have to use the "SendMessage" making it easier and greatly simplifies the developers work.
First you have to install the software on your system "Microsoft Video for Windows SDK" that contains the library avicap32.dll.
Among the functions contained use "capCreateCaptureWindowA" to initialize the driver and image capture.
After handling the capture window will have to use the "SendMessage" making it easier and greatly simplifies the developers work.
Now we are goint to the program:
We add global variables:
Ventana: hwnd; //Handle de la ventana de captura
In the section "const" we write
WM_CAP_START = WM_USER;
WM_CAP_STOP = WM_CAP_START + 68;
WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
WM_CAP_SAVEDIB = WM_CAP_START + 25;
WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
WM_CAP_SEQUENCE = WM_CAP_START + 62;
WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
WM_CAP_EDIT_COPY = WM_CAP_START + 30;
WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52;
Section "implementation":
FUNCTION capCreateCaptureWindowA(lpszWindowName: PCHAR; dwStyle: longint; x: integer; y: integer; nWidth: integer; nHeight: integer; ParentWin: HWND; nId: integer): HWND; STDCALL EXTERNAL 'AVICAP32.DLL';
is the call of the external library Avicap32.dll
Elements of the interface:
-Botón "iniciar" (Pressing start capturing the image from the Webcam)
-Botón "detener" (Press to stop capturing)
-Control de Imagen "tImage" (We called "Image1")
We add global variables:
Ventana: hwnd; //Handle de la ventana de captura
In the section "const" we write
WM_CAP_START = WM_USER;
WM_CAP_STOP = WM_CAP_START + 68;
WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
WM_CAP_SAVEDIB = WM_CAP_START + 25;
WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
WM_CAP_SEQUENCE = WM_CAP_START + 62;
WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
WM_CAP_EDIT_COPY = WM_CAP_START + 30;
WM_CAP_SET_PREVIEW = WM_CAP_START + 50;
WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52;
Section "implementation":
FUNCTION capCreateCaptureWindowA(lpszWindowName: PCHAR; dwStyle: longint; x: integer; y: integer; nWidth: integer; nHeight: integer; ParentWin: HWND; nId: integer): HWND; STDCALL EXTERNAL 'AVICAP32.DLL';
is the call of the external library Avicap32.dll
Elements of the interface:
-Botón "iniciar" (Pressing start capturing the image from the Webcam)
-Botón "detener" (Press to stop capturing)
-Control de Imagen "tImage" (We called "Image1")
The code to be included within the buttons is as follows:
Botón "Iniciar"
PROCEDURE TForm1.Button1Click(Sender: TObject); BEGIN Ventana := capCreateCaptureWindowA('Ventana de captura', WS_CHILD OR WS_VISIBLE, image1.Left, image1.Top, image1.Width, image1.Height, form1.Handle, 0); IF Ventana <> 0 THEN BEGIN TRY SendMessage(Ventana, WM_CAP_DRIVER_CONNECT, 0, 0); SendMessage(Ventana, WM_CAP_SET_PREVIEWRATE, 40, 0); SendMessage(Ventana, WM_CAP_SET_PREVIEW, 1, 0); EXCEPT RAISE; END; END ELSE BEGIN MessageDlg('Error al conectar Webcam', mtError, [mbok], 0); END; END;
Botón "Detener"
PROCEDURE TForm1.Button2Click(Sender: TObject); BEGIN IF Ventana <> 0 THEN BEGIN SendMessage(Ventana, WM_CAP_DRIVER_DISCONNECT, 0, 0); Ventana := 0; END; END;
In the event: Onclose we make a call to the procedure included in the button "Detener".
And that's all for now, we will be adding more items and tips.
Related links:
Webcam con Delphi ( II )
WebCam con Delphi ( III )