1. Dashboard
  2. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team
    4. Mitgliedersuche
  3. Forenregeln
  4. Forum
    1. Unerledigte Themen
  • Anmelden
  • Registrieren
  • Suche
Alles
  • Alles
  • Artikel
  • Seiten
  • Forum
  • Erweiterte Suche
  1. AutoIt.de - Das deutschsprachige Forum.
  2. Mitglieder
  3. Meeshaill

Beiträge von Meeshaill

  • DLL Problem bei Imagesearch

    • Meeshaill
    • 5. September 2015 um 17:19

    Auch Dir noch ein herzliches Dankeschön für den Hinweis. Ich werde an meinem Stil arbeiten :)

  • DLL Problem bei Imagesearch

    • Meeshaill
    • 4. September 2015 um 22:40

    Meinst Du mein Imagesearch Script? Falls ja, das sieht wie folgt aus:

    AutoIt
    #include-once
    ; ------------------------------------------------------------------------------
    ;
    ; AutoIt Version: 3.0
    ; Language:       English
    ; Description:    Functions that assist with Image Search
    ;                 Require that the ImageSearchDLL.dll be loadable
    ;
    ; ------------------------------------------------------------------------------
    
    
    ;===============================================================================
    ;
    ; Description:      Find the position of an image on the desktop
    ; Syntax:           _ImageSearchArea, _ImageSearch
    ; Parameter(s):
    ;                   $findImage - the image to locate on the desktop
    ;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
    ;                                image differ from desktop. e.g GIF
    ;                   $resultPosition - Set where the returned x,y location of the image is.
    ;                                     1 for centre of image, 0 for top left of image
    ;                   $x $y - Return the x and y location of the image
    ;
    ; Return Value(s):  On Success - Returns 1
    ;                   On Failure - Returns 0
    ;
    ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
    ;       a desktop region to search
    ;
    ;===============================================================================
    Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0)
       return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
    EndFunc
    
    
    Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0)
    	;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    	if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    If IsString($findImage) Then
    	$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
    Else
    	$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
    EndIf
    
    
    	; If error exit
        if $result[0]="0" then return 0
    
    
    	; Otherwise get the x,y location of the match and the size of the image to
    	; compute the centre of search
    	$array = StringSplit($result[0],"|")
    
    
       $x=Int(Number($array[2]))
       $y=Int(Number($array[3]))
       if $resultPosition=1 then
          $x=$x + Int(Number($array[4])/2)
          $y=$y + Int(Number($array[5])/2)
       endif
       return 1
    EndFunc
    
    
    ;===============================================================================
    ;
    ; Description:      Wait for a specified number of seconds for an image to appear
    ;
    ; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
    ; Parameter(s):
    ;					$waitSecs  - seconds to try and find the image
    ;                   $findImage - the image to locate on the desktop
    ;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
    ;                                image differ from desktop. e.g GIF
    ;                   $resultPosition - Set where the returned x,y location of the image is.
    ;                                     1 for centre of image, 0 for top left of image
    ;                   $x $y - Return the x and y location of the image
    ;
    ; Return Value(s):  On Success - Returns 1
    ;                   On Failure - Returns 0
    ;
    ;
    ;===============================================================================
    Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance,$HBMP=0)
    	$waitSecs = $waitSecs * 1000
    	$startTime=TimerInit()
    	While TimerDiff($startTime) < $waitSecs
    		sleep(100)
    		$result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP)
    		if $result > 0 Then
    			return 1
    		EndIf
    	WEnd
    	return 0
    EndFunc
    
    
    ;===============================================================================
    ;
    ; Description:      Wait for a specified number of seconds for any of a set of
    ;                   images to appear
    ;
    ; Syntax:           _WaitForImagesSearch
    ; Parameter(s):
    ;					$waitSecs  - seconds to try and find the image
    ;                   $findImage - the ARRAY of images to locate on the desktop
    ;                              - ARRAY[0] is set to the number of images to loop through
    ;								 ARRAY[1] is the first image
    ;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
    ;                                image differ from desktop. e.g GIF
    ;                   $resultPosition - Set where the returned x,y location of the image is.
    ;                                     1 for centre of image, 0 for top left of image
    ;                   $x $y - Return the x and y location of the image
    ;
    ; Return Value(s):  On Success - Returns the index of the successful find
    ;                   On Failure - Returns 0
    ;
    ;
    ;===============================================================================
    Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance,$HBMP=0)
    	$waitSecs = $waitSecs * 1000
    	$startTime=TimerInit()
    	While TimerDiff($startTime) < $waitSecs
    		for $i = 1 to $findImage[0]
    		    sleep(100)
    		    $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP)
    		    if $result > 0 Then
    			    return $i
    		    EndIf
    		Next
    	WEnd
    	return 0
    EndFunc
    Alles anzeigen

    Die beiden Scripte werden einfach nur nacheinander aufgerufen. Also als erstes das Script im ersten Post und dann Imagesearch und wie gesagt, beide funktionieren für sich.

    Allerdings könnte es wohl wirklich an der " Opt("MustDeclareVars", 1)" Anweisung liegen. Das hatte ich bisher nicht bedacht, dass Imagesearch ohne klare Deklaration programmiert ist und es deshalb, weil diese Einstellung global ist zu Problemen kommt. Ich werde das gleich mal testen.


    Alles klar, es war tatsächlich die Einstellung, dass Variablen deklariert werden müssen. Vielleicht mache ich mein Imagesearch also mal wasserdicht bei Gelegenheit. Sorry für diese Tomaten auf den Augen :)


    Lösung des Problems war also: Entweder in Imagesearch die Variablen korrekt deklarieren oder aber die Anweisung "Opt("MustDeclareVars", 1)" entfernen

  • DLL Problem bei Imagesearch

    • Meeshaill
    • 4. September 2015 um 17:43

    Ich habe noch etwas weiter nach Lösungen gesucht, bin damit allerdings wirklich überfragt. Das Problem scheint dadurch hervorgerufen zu werden, dass irgendein Handle geschlossen wird, den Imagesearch später noch verwenden will, vermute ich. Weiß denn niemand woran das liegen könnte?

    Oder könnte es sein, dass Opt("MustDeclareVars", 1) eine globale Einstellung ist, die dann wiederum negative Konsequenzen für Imagesearch hat, weil die Einstellung zu einem Fehler in Imagesearch führt?

  • DLL Problem bei Imagesearch

    • Meeshaill
    • 31. August 2015 um 20:59

    Hallo zusammen,

    ich bin nicht ganz neu, was die Nutzung von Autoit angeht, allerdings auch kein Profi und habe ein Problem, welches mich schon ein paar Tage beschäftigt, weshalb ich nun hoffe bei euch eine Erklärung dafür zu finden.

    Ich arbeite gerade an einem selbstlernenden Programm, welches versucht Formen zu erkennen, zu speichern und wieder zu finden. Dafür habe ich zwei Funktionen, die für sich auch beide funktionieren, nur wenn ich sie kombiniere kommt ein Fehler dabei heraus, der die Imagesearch Funktion unterbricht und wie folgt lautet:

    Code
    $result= DllCall("ImageSearchDLL.dll", "str", "Imagesearch", "int" $x1, "int", $y1, "int" $right, "int", $bottom, "str", $findImage, "ptr", $HBMP) 
    ^Error
    
    
    Error: Variable used without being declared.


    Wie gesagt, für sich funktioniert die ImageSearch Funktion problemlos nur in Kombination mit den folgenden Funktionen nicht. Ich kann den Code leider nicht verkürzen, da ich nicht weiß, was mein Problem hervorruft. Ich wäre euch echt dankbar, wenn jemand mein Wissen mit zumindest einem hilfreichen Hinweis erhellen könnte.

    AutoIt
    Func _ImageReference($path, $name, $number)
    	Opt("MustDeclareVars", 1)
    
    
    	_GDIPlus_Startup()
    	Dim $pixelarray
    	Dim $referenceArray
    	Local $arrayWidth = 0
    	Local $arrayHeight = 0
    	Local $reference = $path & $name & "1.png" ; "image1-before.png" ;
    	Local $file_in = $path & $name & $number & ".png" ; "image1-before.png" ;
    	Local $file_out = $path & $name & $number & ".png"
    	_FileImageToArray($file_in, $pixelarray, $arrayWidth, $arrayHeight)
    	_FileImageToArray($reference, $referenceArray, $arrayWidth, $arrayHeight)
            ;Turn pre defined Areas black
    	For $y = 0 To $arrayHeight - 1 Step 1
    		For $z = 0 To $arrayWidth - 1 Step 1
    			If $referenceArray[$z][$y] = "FFFFFFFF" Then
    				$pixelarray[$z][$y] = "FFFFFFFF"
    			EndIf
    		Next
    	Next
    
    
    	_FileArrayToImage($file_out, $pixelarray)
    	_GDIPlus_Shutdown()
    EndFunc   ;==>_ImageReference
    
    
    Func _FileImageToArray($filename, ByRef $aArray, ByRef $arrayWidth, ByRef $arrayHeight)
    	Local $Reslt, $stride, $format, $Scan0, $iW, $iH, $hImage
    	Local $v_Buffer, $width, $height
    	Local $i, $j
    
    
    	$hImage = _GDIPlus_ImageLoadFromFile($filename)
    	$iW = _GDIPlus_ImageGetWidth($hImage)
    	$iH = _GDIPlus_ImageGetHeight($hImage)
    	$Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    
    
    	;Get the returned values of _GDIPlus_BitmapLockBits ()
    	$width = DllStructGetData($Reslt, "width")
    	$height = DllStructGetData($Reslt, "height")
    	$stride = DllStructGetData($Reslt, "stride")
    	$format = DllStructGetData($Reslt, "format")
    	$Scan0 = DllStructGetData($Reslt, "Scan0")
    
    
    	$arrayHeight = $height
    	$arrayWidth = $width
    
    
    	Dim $aArray[$width][$height]
    	For $i = 0 To $iW - 1
    		For $j = 0 To $iH - 1
    			$v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4))
    			$aArray[$i][$j] = Hex(DllStructGetData($v_Buffer, 1), 8)
    		Next
    	Next
    	_GDIPlus_BitmapUnlockBits($hImage, $Reslt)
    	_GDIPlus_ImageDispose($hImage)
    	Return
    EndFunc   ;==>_FileImageToArray
    
    
    Func _FileArrayToImage($filename, $aArray)
    	Local $iW = UBound($aArray, 1), $iH = UBound($aArray, 2), $sResult = ""
    	Local $hBMP2, $hImage1, $Reslt, $width, $height, $stride, $format, $Scan0
    	Local $sResult, $v_BufferA
    	Local $i, $j
    
    
    	$hBMP2 = _WinAPI_CreateBitmap($iW, $iH, 1, 32)
    	$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP2)
    	$Reslt = _GDIPlus_BitmapLockBits($hImage1, 0, 0, $iW, $iH, $GDIP_ILMWRITE, $GDIP_PXF32ARGB)
    
    
    	;Get the returned values of _GDIPlus_BitmapLockBits ()
    	$width = DllStructGetData($Reslt, "width")
    	$height = DllStructGetData($Reslt, "height")
    	$stride = DllStructGetData($Reslt, "stride")
    	$format = DllStructGetData($Reslt, "format")
    	$Scan0 = DllStructGetData($Reslt, "Scan0")
    
    
    	$v_BufferA = DllStructCreate("DWORD[" & $height * $width & "]", $Scan0)
    
    
    	For $j = 0 To $height - 1
    		For $i = 0 To $width - 1
    			DllStructSetData($v_BufferA, 1, Execute("0x" & $aArray[$i][$j]), ($j * $width) + $i + 1) ; "+1" - base 1.
    		Next
    	Next
    
    
    	_GDIPlus_BitmapUnlockBits($hImage1, $Reslt)
    	_GDIPlus_ImageSaveToFile($hImage1, $filename)
    
    
    	_GDIPlus_ImageDispose($hImage1)
    	_WinAPI_DeleteObject($hBMP2)
    	Return
    EndFunc   ;==>_FileArrayToImage
    Alles anzeigen

    Viele Grüße und vielen Dank vorab an jeden der sich die Mühe macht hier mal drüber zu schauen.


    Lösung des Problems war: Entweder in Imagesearch die Variablen korrekt deklarieren oder aber die Anweisung "Opt("MustDeclareVars", 1)" entfernen

Spenden

Jeder Euro hilft uns, Euch zu helfen.

Download

AutoIt Tutorial
AutoIt Buch
Onlinehilfe
AutoIt Entwickler
  1. Datenschutzerklärung
  2. Impressum
  3. Shoutbox-Archiv
Community-Software: WoltLab Suite™