Jump to content

Recommended Posts

Posted (edited)

I'm trying to adapt the script posted here https://www.autoitscript.com/forum/topic/150536-simple-webcam-access-using-escapi/#comment-1136331 by mylise to display the webcam video and then save the picture .jpg but do not want to use the _ScreenCapture_Capture () does anyone know how to capture the specific area of the GUI and save to jpg?

Changes I've ever done:

;Font ==> https://www.autoitscript.com/forum/topic/150536-simple-webcam-access-using-escapi/#comment-1136331

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>

Global $Width = 640 ;Escapi seems to use 640x480 (or lower) as webcam resolution and will
Global $Height = 480 ; adjust the image size to $Width by $Height

;--------------------------------------------------------------------------
; variables required for dshow escapi
Local $tagSimpleCapParams = _
        "ptr mTargetBuf;" & _
        "int mWidth;" & _
        "int mHeight;"
Local $tSimpleCapParams = DllStructCreate($tagSimpleCapParams)
Local $tTargetBuf = DllStructCreate("BYTE[" & $Width * $Height * 4 & "]")
Global $pTargetBuf = DllStructGetPtr($tTargetBuf)
DllStructSetData($tSimpleCapParams, 1, $pTargetBuf)
DllStructSetData($tSimpleCapParams, 2, $Width)
DllStructSetData($tSimpleCapParams, 3, $Height)
Local $pSimpleCapParams = DllStructGetPtr($tSimpleCapParams)
;--------------------------------------------------------------------------

;---------------------------------------------------------------------------
;Escapi init
Local $_escapi_Dll = DllOpen("escapi.dll")
DllCall($_escapi_Dll, "int:cdecl", "initCapture", "int", 0, "ptr", $pSimpleCapParams)
;---------------------------------------------------------------------------

;---------------------------------------------------------------------------
; GUI create
Global $hwnd = GUICreate("EscApi WebCam", 680, 520)
GUISetBkColor(0x000000, $hwnd)
GUISetState(@SW_SHOW, $hwnd)
;---------------------------------------------------------------------------

;---------------------------------------------------------------------------
; GDI init
_GDIPlus_Startup()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
;---------------------------------------------------------------------------

While 1
    video()
    Local $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Clean_up()
        ExitLoop
    EndIf
    Sleep(50)
WEnd

Func Clean_up()
    $return = DllCall($_escapi_Dll, "none:cdecl", "deinitCapture", "int", 0)
    DllClose($_escapi_Dll)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hwnd)
EndFunc   ;==>Clean_up

Func video()
    ;---------------------------------------------------------------------------
    ;Get frame
    DllCall($_escapi_Dll, "none:cdecl", "doCapture", "int", 0)
    Do
        $return = DllCall($_escapi_Dll, "int:cdecl", "isCaptureDone", "int", 0)
        Sleep(50)
    Until $return[0] = 1
    ;---------------------------------------------------------------------------
    ;Display frame
    $hBMP = _WinAPI_CreateBitmap($Width, $Height, 1, 32, $pTargetBuf)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 20, 20, $Width, $Height)
    _GDIPlus_BitmapDispose($hImage)
    _WinAPI_DeleteObject($hBMP)
    ;---------------------------------------------------------------------------
EndFunc   ;==>video

 

Edited by Belini
Posted (edited)

You can save your bitmap instead make a screen capture.

_WinAPI_SaveHBITMAPToFile  bitmap

_GDIPlus_ImageSaveToFile ObjectBitmap

Saludos

Edited by Danyfirex
Posted (edited)

@Computergroove Full screen I can capture and also can resize but I want to put the webcam image as a control and I want to save the image to appear in the GUI without having to hide gui or having to put the gui in full screen!

@Danyfirex I'll experiment with these commands you posted!

Edited by Belini

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...