Auch Dir noch ein herzliches Dankeschön für den Hinweis. Ich werde an meinem Stil arbeiten
Beiträge von Meeshaill
-
-
Meinst Du mein Imagesearch Script? Falls ja, das sieht wie folgt aus:
AutoIt
Alles anzeigen#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
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 -
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?
-
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
Alles anzeigenFunc _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
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