Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate


  • Please log in to reply
63 replies to this topic
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

I didn't fully understand what you mean.

It is possible to have 2 variables, each one referring to a different bitmap pointer.


Do you mean "search for A... if not found, then search for B"?

;; define here haystack, needle1 and needle2 accordingly,
;; with Gdip_CreateBitmapFromFile() or Gdip_BitmapFromScreen()

if ( 0 >= Gdip_ImageSearch(... needle1 in haystack ...) )    ;; // if Needle1 not found in Haystack
    MsgBox, Needle1 not found. Checking Needle2.
    if ( 0 >= Gdip_ImageSearch(... needle2 in haystack ...) )   ;; // if Needle2 not found in Haystack
        MsgBox, Needle2 not found.


Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.

  • Members
  • 18 posts
  • Last active: Apr 09 2014 04:23 PM
  • Joined: 16 Feb 2014

posted in a couple of places and havent got a reply but

so i changed it abit and it works using Gdip_CreateBitmapFromFile for the haystack and the needle but when i want to use the screen as the haystack, it returns -1001 all the time. Its definately there.what am i doing wrong?

this is what 1001 means:
; -1001 ==> invalid haystack and/or needle bitmap pointer

although im not sure what it actually means  :D ha

heres updated code (pretty much same as MasterFocus)..


;ListLines, Off
SetBatchLines, -1
Process, Priority,, High

#Include <Gdip>
#Include <Gdip_ImageSearch>

gdipToken := Gdip_Startup()
bmpHaystack := Gdip_BitmapFromScreen("33|60|451|305")
bmpNeedle := Gdip_CreateBitmapFromFile("C:\Users\avfc1992\Pictures\image.png")
RET := Gdip_ImageSearch(bmpHaystack,bmpNeedle,LIST)
MsgBox, % "Returned: " RET "`n`n" LIST

  • Members
  • 3 posts
  • Last active: Nov 24 2014 03:55 AM
  • Joined: 23 Nov 2014

MasterFocus, great work! I found a bug:


Searching for an entire screen works, but if I input coordinates for a smaller rectangle, it stopped working for me. Using 64-bit GDIP.


E.g. 0,0,0,0 coordinates work, but any other coordinates including  0, 0, A_ScreenWidth, A_ScreenHeight does  not


I got it working by commenting out lines 92, 93, 118, and 119 in the Gdip_ImageSearch function, the "OR !(hWidth ..." functions were borking the values. I don't know what other side effects this has, but for now I,m back up and running.

  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

@Andargor, MasterFocus doesn't come around here often, if at all. I found it more intuitive to set the image itself to the correct coordinates, then use that in the search. Here's a link to a post I just made about a function I wrote to replace the default ImageSearch: http://www.autohotke...ch-alternative/

OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++