Sign in to follow this  
Followers 0
MuffettsMan

Can PixelSearch return all matches instead of the first one?

3 posts in this topic

trying to find an easy way to get PixelSearch to return all matches in a given area instead of just the first... hopefully there is an easier way than trying to reshape the searchable window >.<


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites



atm... all i have been able to think of is loop single line by line over and over adding any match to an array, and researching the rest of the line after the matched cord in case of multiple matches on a single line.... *oh the pain*


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

trying to find an easy way to get PixelSearch to return all matches in a given area instead of just the first... hopefully there is an easier way than trying to reshape the searchable window >.<

You may be able to use this example. Or, adapt it to suit your needs.

This returns an array all matches of a specified colour in a specified area.

#include <WinAPI.au3>
  #include <ScreenCapture.au3>
  #include <GDIPlus.au3>
  #include <Array.au3>
  
  Opt("MouseCoordMode", 1);1=absolute, 0=relative, 2=client
  
  Dim $iLeft = 30, $iTop = 30, $iRight = 250, $iBottom = 250
  
  Local $aPixels = PixelSearchA($iLeft, $iTop, $iRight, $iBottom, "F000FF")
  
  _ArrayDisplay($aPixels)
  
;Returns an array of the colours found and its absolute position
;$iColor in RRGGBB hexidecimal colour format
  Func PixelSearchA($iLeft, $iTop, $iRight, $iBottom, $iColor = "FFFFFF", $Hwnd = "")
      If $Hwnd = "" Then $Hwnd = WinGetHandle("")
      $iColor = StringRight($iColor, 2) & StringMid($iColor, 3, 2) & StringLeft($iColor, 2); To GBR
      $hBitmap = _ScreenCapture_CaptureWnd("", $Hwnd, $iLeft, $iTop, $iRight, $iBottom, False)
      _GDIPlus_Startup()
      $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
      $width = _GDIPlus_ImageGetWidth($hImage)
      $height = _GDIPlus_ImageGetHeight($hImage)
      $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
      $aSize = DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', 0, 'ptr', 0)
      If $aSize[0] Then
          $tBits = DllStructCreate('byte[' & $aSize[0] & ']')
          DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $hBmp, 'int', $aSize[0], 'ptr', DllStructGetPtr($tBits))
          $sHex = DllStructGetData($tBits, 1)
      EndIf
      Local $sREResult1 = StringRegExp(StringTrimLeft($sHex, 2), "(.{8})", 3)
      Dim $aDiff[UBound($sREResult1)][3]
      Local $iCnt = -1, $sChange
      Local $aPos = WinGetPos($Hwnd)
      For $n = 0 To UBound($sREResult1) - 1
          If $sREResult1[$n] = $iColor & "FF" Then
              $iCnt += 1
              Local $bgr = StringTrimRight($sREResult1[$n], 2)
              $aDiff[$iCnt][0] = StringRight($bgr, 2) & StringMid($bgr, 3, 2) & StringLeft($bgr, 2)
              $aDiff[$iCnt][1] = ($n + 1) - (Int(($n) / $height)) * $width + $iLeft - 1 + $aPos[0]
              $aDiff[$iCnt][2] = Int(($n) / $height) + $iTop + $aPos[1]
          EndIf
      Next
      If $iCnt > 0 Then
          ReDim $aDiff[$iCnt + 1][3]
      Else
          local  $aDiff[1] = ["No match found"]
      EndIf
      _WinAPI_DeleteObject($hBitmap)
      _WinAPI_DeleteObject($hBmp)
      _GDIPlus_ImageDispose($hImage)
      _GDIPlus_Shutdown()
      Return $aDiff
  EndFunc
Edited by Malkey

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0