с помощью клиент сервера
server
клиент
библиотека Webcam.au3
server
Код:
#include <WindowsConstants.au3>
#include <Webcam.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>
_GDIPlus_Startup()
TCPStartup()
$listen = TCPListen("ip", порт )
Do
$tcp = TCPAccept($listen)
Until $tcp <> -1
$gui = GUICreate("Webcam", 160, 120)
$dll_avi = DllOpen("avicap32.dll")
$dll_user = DllOpen("user32.dll")
$cap = DllCall($dll_avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD, $WS_VISIBLE), "int", 0, "int", 0, "int", 160, "int", 120, "hwnd", $gui, "int", 1)
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
GUISetState(@SW_SHOW)
$timer = TimerInit()
$fps = 10
While 1
If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then
ExitLoop
EndIf
If (TimerDiff($timer) > 1000 / $fps) Then
$timer = TimerInit()
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", "temp.bmp")
$img = _GDIPlus_ImageLoadFromFile("temp.bmp")
_GDIPlus_ImageSaveToFile($img, "temp.jpg")
_GDIPlus_ImageDispose($img)
TCPSend($tcp, StringToBinary(FileRead("temp.jpg")))
EndIf
WEnd
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_END, "int", 0, "int", 0)
DllCall($dll_user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
DllClose($dll_user)
клиент
Код:
#include <GUIConstants.au3>
GUICreate("Test", 320, 240)
$pic = GUICtrlCreatePic("", 0, 0, 320, 240)
GUISetState(@SW_SHOW)
TCPStartup()
$tcp = TCPConnect("ip", порт)
While 1
If (GUIGetMsg() = $GUI_EVENT_CLOSE) Then
ExitLoop
EndIf
$r = TCPRecv($tcp, 1024)
FileWrite("tcp.jpg", Binary($r))
If (BinaryMid($r, BinaryLen($r)-1, 2) = "0xFFD9") Then
GUICtrlSetImage($pic, "tcp.jpg")
FileDelete("tcp.jpg")
EndIf
WEnd
библиотека Webcam.au3