was besseres als _ClipBoard_

  • hi @ all ,

    hab da mal ne Frage.

    hier ist ein Progrämmle, mit dem man ein Web-Cam steam um 90 grad drehen kann.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <ClipBoard.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("TrayIconHide", 1)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $Gridstep=50 ;Abstand zwischen den Pixeln zum Abtasten

    [/autoit] [autoit][/autoit] [autoit]

    $sensitivity = 15 ;Empfindlichkeit

    [/autoit] [autoit][/autoit] [autoit]

    $gui_x=300;@DesktopWidth-(@DesktopWidth/8)
    $gui_y=300;@DesktopHeight-(@DesktopHeight/8)
    $top = $CMDLINE[4] ;150
    $left = $CMDLINE[3] ;160
    $TopDebug = $CMDLINE[6] ;162
    $LeftDebug = $CMDLINE[5] ;637
    $drehwinkel = $CMDLINE[7] ;90
    $picx = 640
    $picy = 480

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $width=$gui_x

    [/autoit] [autoit][/autoit] [autoit]

    $cam_xlength=400;(1.3*($width/2)-(2*($width/20)));300 ;Breite (1.3*($width/2)-(2*($width/20)))
    $cam_ylength=400;( $width/2)-(2*($width/20));300 ;Höhe ( $width/2)-(2*($width/20))

    [/autoit] [autoit][/autoit] [autoit]

    ;HotKeySet("{END}", "Quit");
    HotKeySet("{INSERT}", "SnapShot")

    [/autoit] [autoit][/autoit] [autoit]

    Global $snapfile[4]
    $snapfile[0] = @ScriptDir & "\MusterBilder\scrshot1.jpg"
    $snapfile[1] = @ScriptDir & "\MusterBilder\scrshot2.jpg"
    $snapfile[2] = @ScriptDir & "\MusterBilder\scrshot3.jpg"
    $snapfile[3] = @ScriptDir & "\MusterBilder\scrshot4.jpg"
    $snapcount = 0
    $tempbild = @ScriptDir & "\temp.bmp"

    [/autoit] [autoit][/autoit] [autoit]

    #include-once
    $WM_CAP_START = 0x400
    $WM_CAP_UNICODE_START = $WM_CAP_START +100
    $WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
    $WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
    $WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
    $WM_CAP_ABORT = $WM_CAP_START + 69
    $WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
    $WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
    $WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
    $WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
    $WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
    $WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
    $WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
    $WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
    $WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
    $WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
    $WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
    $WM_CAP_EDIT_COPY = $WM_CAP_START + 30
    $WM_CAP_END = $WM_CAP_UNICODE_END
    $WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
    $WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
    $WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
    $WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
    $WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
    $WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
    $WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
    $WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
    $WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
    $WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
    $WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
    $WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
    $WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
    $WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
    $WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
    $WM_CAP_GET_STATUS = $WM_CAP_START + 54
    $WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
    $WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
    $WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
    $WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
    $WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
    $WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
    $WM_CAP_PAL_OPENA = $WM_CAP_START + 80
    $WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
    $WM_CAP_PAL_PASTE = $WM_CAP_START + 82
    $WM_CAP_SEQUENCE = $WM_CAP_START + 62
    $WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
    $WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
    $WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
    $WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
    $WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
    $WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
    $WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
    $WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
    $WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
    $WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
    $WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
    $WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
    $WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
    $WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
    $WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
    $WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
    $WM_CAP_SET_SCALE = $WM_CAP_START + 53
    $WM_CAP_SET_SCROLL = $WM_CAP_START + 55
    $WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
    $WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
    $WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
    $WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
    $WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
    $WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
    $WM_CAP_STOP = $WM_CAP_START + 68

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $avi = DllOpen("avicap32.dll")
    $user = DllOpen("user32.dll")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $gui_name=$CMDLINE[1]

    [/autoit] [autoit][/autoit] [autoit]

    ;$gui = GUICreate($gui_name,$gui_x,$gui_y)
    ;$gui = GUICreate($gui_name,$gui_x,$gui_y, $top, $left, $WS_BORDER, $WS_EX_TOPMOST)
    ;$gui = GUICreate("sodele", 1600, 1000, 0, 0, -1, $WS_EX_TOPMOST) ; generierung des haupt fensters

    [/autoit] [autoit][/autoit] [autoit]

    ;$WebcamID = _WebcamOpen($gui, 0, 0, $cam_xlength, $cam_ylength)
    ;$WebcamID = _WebcamOpen($gui, 10, 10, $cam_xlength, $cam_ylength)
    $WebcamID = _WebcamOpen($CMDLINE[2], $leftDebug, $topDebug, $cam_xlength, $cam_ylength)

    [/autoit] [autoit][/autoit] [autoit]

    ;GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    $hMatrix = _GDIPlus_MatrixCreate()
    ;_GDIPlus_MatrixTranslate($hMatrix, $left+$picy, $top)
    _GDIPlus_MatrixTranslate($hMatrix, $left, $top+$picx)
    _GDIPlus_MatrixRotate($hMatrix, $drehwinkel)
    ;$hGraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($CMDLINE[1])
    _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1

    [/autoit] [autoit][/autoit] [autoit]

    sleep(5)

    [/autoit] [autoit][/autoit] [autoit]

    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
    _WebcamClose($WebcamID)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    _Drehen()

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func SnapShot()
    _WebcamSnap($WebcamID, $snapfile[$snapcount])
    $snapcount += 1
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Quit()
    _WebcamClose($WebcamID)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Drehen()
    DllCall($user, "int", "SendMessage", "hWnd", $WebcamID, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $WebcamID, "int", $WM_CAP_EDIT_COPY, "int", 0, "int", 0)
    sleep(10)
    _ClipBoard_Open ($CMDLINE[2])
    $hImageCB = _ClipBoard_GetDataEx ($CF_BITMAP )
    ;If $hImageCB = 0 Then _WinAPI_ShowError ("Mist hImageCB")
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP( $hImageCB )
    ;If $hImage = 0 Then _WinAPI_ShowError ("Mist hImage")
    _WinAPI_DeleteObject($hImageCB)
    _ClipBoard_Close ()
    ;$iWidth = _GDIPlus_ImageGetWidth($hImage) * 96 / _GDIPlus_ImageGetVerticalResolution($hImage)
    ;$iHeight = _GDIPlus_ImageGetHeight($hImage) * 96 / _GDIPlus_ImageGetHorizontalResolution($hImage)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    ;_GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hImage)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Open's a webcam preview screen in your gui
    ; Syntax: _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
    ; Parameter(s): $sHwnd - The handle of the gui
    ; $sLeft - Left coord. of the preview screen
    ; $sTop - Top coord. of the preview screen
    ; $sWidth - Width of the preview screen
    ; $sHeight - Height of the preview screen
    ; Requirement(s): A webcam
    ; Return Value(s): On Success - Returns id needed for other controls
    ; On Failure - Returns -1
    ; Author(s): Ludocus
    ; Note(s): None
    ;
    ;===============================================================================
    func _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
    ;$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1)
    $cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1)
    DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
    if @error then return -1
    return $cap[0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Creates a Snapshot from a webcam
    ; Syntax: _WebcamSnap($sId, $sFile)
    ; Parameter(s): $sId - Id (returned from _WebcamOpen)
    ; $sFile - File to save the snapshot to (*.bmp)
    ; Requirement(s): A webcam
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0
    ; Author(s): Ludocus
    ; Note(s): None
    ;
    ;===============================================================================
    Func _WebcamSnap($sId, $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $WebcamID, "int", $WM_CAP_EDIT_COPY, "int", 0, "int", 0)
    sleep(10)
    _ClipBoard_Open ($CMDLINE[2])
    $hImageCB1 = _ClipBoard_GetDataEx ($CF_BITMAP )
    If $hImageCB1 = 0 Then _WinAPI_ShowError ("Mist hImageCB1")
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP( $hImageCB1 )
    If $hImage1 = 0 Then _WinAPI_ShowError ("Mist hImage1")
    _ClipBoard_Close ()

    $hMatrix1 = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix1, $drehwinkel)

    $hGraphic1 = _GDIPlus_ImageGetGraphicsContext($hImage1)
    _GDIPlus_GraphicsSetTransform($hGraphic1, $hMatrix1)
    ;_GDIPlus_GraphicsDrawImage($hGraphic1, $hImage1, 0, 0)
    _GDIPlus_ImageSaveToFile($hImage1, $sFile)
    ;_GDIPlus_BitmapDispose($hImage)
    _GDIPlus_ImageDispose($hImage1)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_MatrixDispose($hMatrix1)
    _GDIPlus_GraphicsDispose($hGraphic1)
    _WinAPI_DeleteObject($hImageCB1)

    ;ALT DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)
    if @error Then
    return 0
    Else
    return 1
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Closes the preview screen created with _WebcamOpen
    ; Syntax: _WebcamClose($sId)
    ; Parameter(s): $sId - Id (returned from _WebcamOpen)
    ; Requirement(s): A webcam
    ; Return Value(s): On Success - Returns 1
    ; On Failure - Returns 0
    ; Author(s): Ludocus
    ; Note(s): None
    ;
    ;===============================================================================
    Func _WebcamClose($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_END, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
    DllClose($user)
    if @error Then
    return 0
    Else
    return 1
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    soweit ist ja alles ganz gut .. und erfüllt seinen zweck.

    jetzt stört mich aber die "dreh" Funktion ..

    Spoiler anzeigen
    [autoit]

    _ClipBoard_Open ($CMDLINE[2])
    $hImageCB = _ClipBoard_GetDataEx ($CF_BITMAP )
    ;If $hImageCB = 0 Then _WinAPI_ShowError ("Mist hImageCB")
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP( $hImageCB )
    ;If $hImage = 0 Then _WinAPI_ShowError ("Mist hImage")
    _WinAPI_DeleteObject($hImageCB)
    _ClipBoard_Close ()
    ;$iWidth = _GDIPlus_ImageGetWidth($hImage) * 96 / _GDIPlus_ImageGetVerticalResolution($hImage)
    ;$iHeight = _GDIPlus_ImageGetHeight($hImage) * 96 / _GDIPlus_ImageGetHorizontalResolution($hImage)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    ;_GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hImage)

    [/autoit]

    im grunde genommen wird der Steam als Bild gespeichert, dann durch eine Matrix gedreht
    und das unter Zuhilfenahme des _ClipBoard_ . . . . was ich echt MIST finde..

    WEIL, wenn man z.B. ein Desctop- abbild macht, schiesst es einem den Video Steam zusammen.

    .. schon weng störend .. und absolut nicht stabil ..

    mir fällt aber absolut nicht ein, wie ich das anders lösen könnte.

    jemand ne Idee ... oder n Tip ??