Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GDI+ standard library 1.45 by tic


  • Please log in to reply
1385 replies to this topic
Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
You must be working for some TV station/network - they're the best I know for taking words out of context and making "news" out of that. Let me translate:

Loop, % all_posters
{
IfExist, % AHKbasic_script_previously_posted_by_you
       FileAppend, %AHKbasic_script_previously_posted_by_you%, autohotkey.net
else
       Continue ; whatever you were doing
}

AHK Basic compatible does not mean AHKL 64 bit incompatible.

I wouldn't know since my machine is 32bit running Windows98SE. Compatibility with other hardware architecture and/or operating system versions is left for users to test.

Please stop hijacking this topic.

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


  • Guests
  • Last active:
  • Joined: --

Let me translate:

I think this is better,
If (you = AHKLHater)
	ExitApp	; just shut up and stay with AHK Basic
Loop, % 
only_posters_planning_to_migrate_to_AHKL
{
IfExist, % AHKbasic_script_previously_posted_by_you
       FileAppend, %AHKbasic_script_previously_posted_by_you%, autohotkey.net
else
       Continue ; whatever you were doing
}

I wouldn't know since my machine is 32bit running Windows98SE. Compatibility with other hardware architecture and/or operating system versions is left for users to test.

Similarly, my machine is 64bit running Windows7. Compatibility with other environments is for users to test. So for those who post AHKL scripts don't need to mention whether the scripts are not compatible with AHK Basic.

Please stop hijacking this topic.

That's you who need to stop hijacking, please.

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

Thanks fincs and all. I really appreciate anyone putting in the work to help out
I posted the machine code for pixelation a bunch of page back if you want to recompile it

Thanks for pointing me to the source code. I've just updated my previous post with a new version of Gdip.ahk.

Note: that C++ code has two (very) nasty bugs: it doesn't check for divisions by zero, and uses the wrong calling convention on x86! It worked before because:[*:2tpejc20]Integer divisions by zero just yield a 0 on x86 (but throw an exception on x64!).
[*:2tpejc20]The calling convention thing throws an exception just after returning, so the bulk of the code is processed. The error itself is silent, since it is catched by DllCall and stored in the ErrorLevel variable.Here's a fixed version:
int [color=red]__stdcall[/color] Gdip_PixelateBitmap(unsigned char * sBitmap, unsigned char * dBitmap, int w, int h, int Stride, int Size)
{
    int sA, sR, sG, sB, rw, rh, o;

    for (int y1 = 0; y1 < h/Size; ++y1)
    {
        for (int x1 = 0; x1 < w/Size; ++x1)
        {
            sA = sR = sG = sB = 0;
            for (int y2 = 0; y2 < Size; ++y2)
            {
                for (int x2 = 0; x2 < Size; ++x2)
                {
                    o = 4*(x2+x1*Size)+Stride*(y2+y1*Size);
                    sA += sBitmap[3+o];
                    sR += sBitmap[2+o];
                    sG += sBitmap[1+o];
                    sB += sBitmap[o];
                }
            }
            
            sA /= Size*Size;
            sR /= Size*Size;
            sG /= Size*Size;
            sB /= Size*Size;
            for (int y2 = 0; y2 < Size; ++y2)
            {
                for (int x2 = 0; x2 < Size; ++x2)
                {
                    o = 4*(x2+x1*Size)+Stride*(y2+y1*Size);
                    dBitmap[3+o] = sA;
                    dBitmap[2+o] = sR;
                    dBitmap[1+o] = sG;
                    dBitmap[o] = sB;
                }
            }
        }
        
        if (w % Size != 0)
        {
            sA = sR = sG = sB = 0;
            for (int y2 = 0; y2 < Size; ++y2)
            {
                for (int x2 = 0; x2 < w % Size; ++x2)
                {
                    o = 4*(x2+(w/Size)*Size)+Stride*(y2+y1*Size);
                    sA += sBitmap[3+o];
                    sR += sBitmap[2+o];
                    sG += sBitmap[1+o];
                    sB += sBitmap[o];
                }
            }
            
            [color=red]{
            int tmp = (w % Size)*Size;
            sA = tmp ? (sA / tmp) : 0;
            sR = tmp ? (sR / tmp) : 0;
            sG = tmp ? (sG / tmp) : 0;
            sB = tmp ? (sB / tmp) : 0;
            }[/color]
            for (int y2 = 0; y2 < Size; ++y2)
            {
                for (int x2 = 0; x2 < w % Size; ++x2)
                {
                    o = 4*(x2+(w/Size)*Size)+Stride*(y2+y1*Size);
                    dBitmap[3+o] = sA;
                    dBitmap[2+o] = sR;
                    dBitmap[1+o] = sG;
                    dBitmap[o] = sB;
                }
            }
        }
    }

    for (int x1 = 0; x1 < w/Size; ++x1)
    {
        sA = sR = sG = sB = 0;
        for (int y2 = 0; y2 < h % Size; ++y2)
        {
            for (int x2 = 0; x2 < Size; ++x2)
            {
                o = 4*(x2+x1*Size)+Stride*(y2+(h/Size)*Size);
                sA += sBitmap[3+o];
                sR += sBitmap[2+o];
                sG += sBitmap[1+o];
                sB += sBitmap[o];
            }
        }
        
        [color=red]{
        int tmp = Size*(h % Size);
        sA = tmp ? (sA / tmp) : 0;
        sR = tmp ? (sR / tmp) : 0;
        sG = tmp ? (sG / tmp) : 0;
        sB = tmp ? (sB / tmp) : 0;
        }[/color]
        for (int y2 = 0; y2 < h % Size; ++y2)
        {
            for (int x2 = 0; x2 < Size; ++x2)
            {
                o = 4*(x2+x1*Size)+Stride*(y2+(h/Size)*Size);
                dBitmap[3+o] = sA;
                dBitmap[2+o] = sR;
                dBitmap[1+o] = sG;
                dBitmap[o] = sB;
            }
        }
    }
    
    sA = sR = sG = sB = 0;
    for (int y2 = 0; y2 < h % Size; ++y2)
    {
        for (int x2 = 0; x2 < w % Size; ++x2)
        {
            o = 4*(x2+(w/Size)*Size)+Stride*(y2+(h/Size)*Size);
            sA += sBitmap[3+o];
            sR += sBitmap[2+o];
            sG += sBitmap[1+o];
            sB += sBitmap[o];
        }
    }
    
    [color=red]{
    int tmp = (w % Size)*(h % Size);
    sA = tmp ? (sA / tmp) : 0;
    sR = tmp ? (sR / tmp) : 0;
    sG = tmp ? (sG / tmp) : 0;
    sB = tmp ? (sB / tmp) : 0;
    }[/color]
    for (int y2 = 0; y2 < h % Size; ++y2)
    {
        for (int x2 = 0; x2 < w % Size; ++x2)
        {
            o = 4*(x2+(w/Size)*Size)+Stride*(y2+(h/Size)*Size);
            dBitmap[3+o] = sA;
            dBitmap[2+o] = sR;
            dBitmap[1+o] = sG;
            dBitmap[o] = sB;
        }
    }
    return 0;
}

There is at least one: me. There may be others too, although they may not be posting all around the forum board.

Apparently you failed to realize that I was saying it tongue-in-cheek, hence the laugh smiley. Obviously there still are AHK Basic users, namely those whose OS doesn't support AHK_L, those who haven't yet noticed that there's a new version and those who can't upgrade for some other reason.

tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007

Note: that C++ code has two (very) nasty bugs: it doesn't check for divisions by zero, and uses the wrong calling convention on x86!


Calling convention is fine :)

<!-- m -->http://www.autohotke... ... 033#419033<!-- m -->

Also, all of that isn't needed for division by 0. I accidentally just missed out

if (h % Size != 0)


GollyJer
  • Members
  • 24 posts
  • Last active: Dec 21 2012 06:35 PM
  • Joined: 15 Oct 2007
EDIT

Decided to create a separate, more clear, description of the problem in it's own thread.

/EDIT

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Why don't all functions have the gdip_ prefix? Things like CreateCompatibleDC() require gdip.ahk to be explicitly #Included :(

infogulch
  • Moderators
  • 717 posts
  • Last active: Jul 31 2014 08:27 PM
  • Joined: 27 Mar 2008
nimda: put it in your library, and do an #include <GDIP>

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010

nimda: put it in your library, and do an #include <GDIP>

Well of course. However all code in the examples has
; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk
This comment is incorrect because functions not prefaced with gdip_ will not be found.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

This comment is incorrect because functions not prefaced with gdip_ will not be found.

Your comment is incorrect if the code is kept in context. Wouldn't the user call Gdip_Startup() first? That would include the entire library if the library is in the Standard Lib folder.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
:oops: Posted Image

tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007
Ok.....I have rewritten Gdip_ImageSearch below to have all the options I think are needed. This will need some testing though, if someone doesn't mind spending an hour doing this and reporting results. Variation can be 0-255. sx and sy are the start x and start y. w and h are the width and height of the rectangle to search.

Please post any bugs or suggestions, and then I will include it in the library

Thanks

Gdip_ImageSearch(pBitmapHayStack, pBitmapNeedle, ByRef x, ByRef y, Variation=0, sx="", sy="", w="", h="")
{
	static _ImageSearch1, _ImageSearch2
	if !_ImageSearch1
	{
		MCode_ImageSearch1 := "83EC108B44242C9983E20303C28BC88B4424309983E20303C253C1F80255894424148B44244056C1F9023B44244C578944244"
		. "80F8DCA0000008B7C24348D148D000000000FAFC88B442444895424148B54242403C88D1C8A8B4C244C895C24183BC1894424407D7A895C24108D6424"
		. "008B6C2428C744243C000000008D6424008B44243C3B4424380F8D9400000033C985FF7E178BD58BF38B063B02752283C10183C20483C6043BCF7CED8"
		. "B44241C035C24148344243C0103C003C003E8EBC08B4424408B5C24108B4C244C83C00183C3043BC189442440895C24107C928B4424448B5424488B5C"
		. "2418035C241483C2013B54245089542448895C24180F8C5DFFFFFF8B5424548B4424585F5EC702FFFFFFFF5DC700FFFFFFFF83C8FF5B83C410C38B4C2"
		. "4548B5424408B4424585F89118B4C24445E5D890833C05B83C410C3"

		VarSetCapacity(_ImageSearch1, StrLen(MCode_ImageSearch1)//2)
		Loop % StrLen(MCode_ImageSearch1)//2		;%
			NumPut("0x" SubStr(MCode_ImageSearch1, (2*A_Index)-1, 2), _ImageSearch1, A_Index-1, "char")
	}

	if !_ImageSearch2
	{
		MCode_ImageSearch2 :="83EC1C8B4424443B44244C535556578944241C0F8D760100008B4C24488B5424580FAFC88B4424608B742440894C24188B4C24"
		. "503BCA894C24140F8D320100008B54241833FF897C24108B5C24103B5C2444897C2428895424240F8D4E01000085F6C7442420000000000F8ECD00000"
		. "08B7424348D148A8B4C243003F7897424548D1C0AEB0A8DA424000000008D49008B6C2454B9030000000FB60C19BE030000000FB6342E8D2C013BF50F"
		. "8FA20000002BC83BF10F8C980000008B4C24300FB64C0A028B7424340FB67437028D2C013BF57F7F2BC83BF17C798B4C24300FB64C0A018B7424340FB"
		. "67437018D2C013BF57F602BC83BF17C5A0FB60B8B7424540FB6368D2C013BF57F492BC83BF17C438B4C24208B742440834424540483C10183C20483C3"
		. "0483C7043BCE894C24200F8C5BFFFFFF8B4C24148B7C24288B542424035424488344241001037C244CE9F7FEFFFF8B4C24148B5424588B74244083C10"
		. "13BCA894C24140F8CD2FEFFFF8B4C24508B7C241C8B5C2448015C241883C7013B7C245C897C241C0F8CA5FEFFFF8B5424648B4424685F5EC702FFFFFF"
		. "FF5DC700FFFFFFFF83C8FF5B83C41CC38B5424648B4424685F890A8B4C24185E5D890833C05B83C41CC3"

		VarSetCapacity(_ImageSearch2, StrLen(MCode_ImageSearch2)//2)
		Loop % StrLen(MCode_ImageSearch2)//2		;%
			NumPut("0x" SubStr(MCode_ImageSearch2, (2*A_Index)-1, 2), _ImageSearch2, A_Index-1, "char")
	}
	
	if (Variation > 255 || Variation < 0)
		return -2

	Gdip_GetImageDimensions(pBitmapHayStack, hWidth, hHeight), Gdip_GetImageDimensions(pBitmapNeedle, nWidth, nHeight)
	
	if !(hWidth && hHeight && nWidth && nHeight)
		return -3
	if (nWidth > hWidth || nHeight > hHeight)
		return -4
	
	sx := (sx = "") ? 0 : sx
	sy := (sy = "") ? 0 : sy
	w := (w = "") ? hWidth-sx : w
	h := (h = "") ? hHeight-sy : h
	
	if (sx+w > hWidth-nWidth)
		w := hWidth-sx-nWidth+1
	
	if (sy+h > hHeight-nHeight)
		h := hHeight-sy-nHeight+1
		
	E1 := Gdip_LockBits(pBitmapHayStack, 0, 0, hWidth, hHeight, Stride1, Scan01, BitmapData1)
	E2 := Gdip_LockBits(pBitmapNeedle, 0, 0, nWidth, nHeight, Stride2, Scan02, BitmapData2)
	if (E1 || E2)
		return -5

	x := y := 0
	if (Variation = 0)
	{
		E := DllCall(&_ImageSearch1, "uint", Scan01, "uint", Scan02, "int", hWidth, "int", hHeight, "int", nWidth, "int", nHeight, "int", Stride1
		, "int", Stride2, "int", sx, "int", sy, "int", w, "int", h, "int*", x, "int*", y)
	}
	else
	{
		E := DllCall(&_ImageSearch2, "uint", Scan01, "uint", Scan02, "int", hWidth, "int", hHeight, "int", nWidth, "int", nHeight, "int", Stride1
		, "int", Stride2, "int", sx, "int", sy, "int", w, "int", h, "int", Variation, "int*", x, "int*", y)
	}
	Gdip_UnlockBits(pBitmapHayStack, BitmapData1), Gdip_UnlockBits(pBitmapNeedle, BitmapData2)
	return E ? E : -6
}

int Gdip_ImageSearch1(unsigned int * HayStack, unsigned int * Needle, int w1, int h1, int w2, int h2, int Stride1, int Stride2, int sx, int sy, int w, int h, int * x, int * y)
{
	int tx, ty;
	int offset1 = Stride1/4, offset2 = Stride2/4;
	for (int y1 = sy; y1 < h; ++y1)
	{
		for (int x1 = sx; x1 < w; ++x1)
		{
			ty = y1;
			for (int y2 = 0; y2 < h2; ++y2)
			{
				tx = x1;
				for (int x2 = 0; x2 < w2; ++x2)
				{
					if (HayStack[tx+(ty*offset1)] != Needle[x2+(y2*offset2)])
					   goto NoMatch;
					tx++;
				}
				ty++;
			}
			x[0] = x1; y[0] = y1;
			return 0;
			NoMatch:
			continue;
		}
	}
	x[0] = -1; y[0] = -1;
	return -1;
}

int Gdip_ImageSearch2(unsigned char * HayStack, unsigned char * Needle, int w1, int h1, int w2, int h2, int Stride1, int Stride2, int sx, int sy, int w, int h, int v, int * x, int * y)
{
	int tx, ty, ph, pn, Ah, Rh, Gh, Bh, An, Rn, Gn, Bn;
	for (int y1 = sy; y1 < h; ++y1)
	{
		for (int x1 = sx; x1 < w; ++x1)
		{
			ty = y1;
			for (int y2 = 0; y2 < h2; ++y2)
			{
				tx = x1;
				for (int x2 = 0; x2 < w2; ++x2)
				{
					ph = (4*tx)+(ty*Stride1);
					pn = (4*x2)+(y2*Stride2);

					Ah = HayStack[3+ph]; An = Needle[3+pn];
					if (An > Ah+v || An < Ah-v) goto NoMatch;

					Rh = HayStack[2+ph]; Rn = Needle[2+pn];
					if (Rn > Rh+v || Rn < Rh-v) goto NoMatch;

					Gh = HayStack[1+ph]; Gn = Needle[1+pn];
					if (Gn > Gh+v || Gn < Gh-v) goto NoMatch;

					Bh = HayStack[ph]; Bn = Needle[pn];
					if (Bn > Bh+v || Bn < Bh-v) goto NoMatch;
					
					tx++;
				}
				ty++;
			}
			x[0] = x1; y[0] = y1;
			return 0;
			NoMatch:
			continue;
		}
	}
	x[0] = -1; y[0] = -1;
	return -1;
}

edit: Needed to add 1:
w := hWidth-sx-nWidth+1
edit: Quick tests show that using no variation is around twice as fast as using variation
edit: Further tests show that it is around 4.5 times faster than ImageSearch
edit: Changed to return E ? E : -6

GollyJer
  • Members
  • 24 posts
  • Last active: Dec 21 2012 06:35 PM
  • Joined: 15 Oct 2007
Hi tic. I'm not the greatest tester because I'm a complete amateur when it comes to your library.
But, here's what my attempt so far.

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

#Include, Gdip.ahk

^!6::
   
   pBitmapHayStack := Gdip_CreateBitmapFromFile("Haystack.png")
   pBitmapNeedle := Gdip_CreateBitmapFromFile("Needle.png")
   
   MsgBox % Gdip_ImageSearch(pBitmapHayStack, pBitmapNeedle, FoundX, FoundY)

Exit


Gdip_ImageSearch(pBitmapHayStack, pBitmapNeedle, ByRef x, ByRef y, Variation=0, sx="", sy="", w="", h="")
{
   static _ImageSearch1, _ImageSearch2
   if !_ImageSearch1
   {
      MCode_ImageSearch1 := "83EC108B44242C9983E20303C28BC88B4424309983E20303C253C1F80255894424148B44244056C1F9023B44244C578944244"
      . "80F8DCA0000008B7C24348D148D000000000FAFC88B442444895424148B54242403C88D1C8A8B4C244C895C24183BC1894424407D7A895C24108D6424"
      . "008B6C2428C744243C000000008D6424008B44243C3B4424380F8D9400000033C985FF7E178BD58BF38B063B02752283C10183C20483C6043BCF7CED8"
      . "B44241C035C24148344243C0103C003C003E8EBC08B4424408B5C24108B4C244C83C00183C3043BC189442440895C24107C928B4424448B5424488B5C"
      . "2418035C241483C2013B54245089542448895C24180F8C5DFFFFFF8B5424548B4424585F5EC702FFFFFFFF5DC700FFFFFFFF83C8FF5B83C410C38B4C2"
      . "4548B5424408B4424585F89118B4C24445E5D890833C05B83C410C3"

      VarSetCapacity(_ImageSearch1, StrLen(MCode_ImageSearch1)//2)
      Loop % StrLen(MCode_ImageSearch1)//2      ;%
         NumPut("0x" SubStr(MCode_ImageSearch1, (2*A_Index)-1, 2), _ImageSearch1, A_Index-1, "char")
   }

   if !_ImageSearch2
   {
      MCode_ImageSearch2 :="83EC1C8B4424443B44244C535556578944241C0F8D760100008B4C24488B5424580FAFC88B4424608B742440894C24188B4C24"
      . "503BCA894C24140F8D320100008B54241833FF897C24108B5C24103B5C2444897C2428895424240F8D4E01000085F6C7442420000000000F8ECD00000"
      . "08B7424348D148A8B4C243003F7897424548D1C0AEB0A8DA424000000008D49008B6C2454B9030000000FB60C19BE030000000FB6342E8D2C013BF50F"
      . "8FA20000002BC83BF10F8C980000008B4C24300FB64C0A028B7424340FB67437028D2C013BF57F7F2BC83BF17C798B4C24300FB64C0A018B7424340FB"
      . "67437018D2C013BF57F602BC83BF17C5A0FB60B8B7424540FB6368D2C013BF57F492BC83BF17C438B4C24208B742440834424540483C10183C20483C3"
      . "0483C7043BCE894C24200F8C5BFFFFFF8B4C24148B7C24288B542424035424488344241001037C244CE9F7FEFFFF8B4C24148B5424588B74244083C10"
      . "13BCA894C24140F8CD2FEFFFF8B4C24508B7C241C8B5C2448015C241883C7013B7C245C897C241C0F8CA5FEFFFF8B5424648B4424685F5EC702FFFFFF"
      . "FF5DC700FFFFFFFF83C8FF5B83C41CC38B5424648B4424685F890A8B4C24185E5D890833C05B83C41CC3"

      VarSetCapacity(_ImageSearch2, StrLen(MCode_ImageSearch2)//2)
      Loop % StrLen(MCode_ImageSearch2)//2      ;%
         NumPut("0x" SubStr(MCode_ImageSearch2, (2*A_Index)-1, 2), _ImageSearch2, A_Index-1, "char")
   }
   
   if (Variation > 255 || Variation < 0)
      return -2

   Gdip_GetImageDimensions(pBitmapHayStack, hWidth, hHeight), Gdip_GetImageDimensions(pBitmapNeedle, nWidth, nHeight)
   
   if !(hWidth && hHeight && nWidth && nHeight)
      return -3
   if (nWidth > hWidth || nHeight > hHeight)
      return -4
   
   sx := (sx = "") ? 0 : sx
   sy := (sy = "") ? 0 : sy
   w := (w = "") ? hWidth-sx : w
   h := (h = "") ? hHeight-sy : h
   
   if (sx+w > hWidth-nWidth)
      w := hWidth-sx-nWidth+1
   
   if (sy+h > hHeight-nHeight)
      h := hHeight-sy-nHeight+1
      
   E1 := Gdip_LockBits(pBitmapHayStack, 0, 0, hWidth, hHeight, Stride1, Scan01, BitmapData1)
   E2 := Gdip_LockBits(pBitmapNeedle, 0, 0, nWidth, nHeight, Stride2, Scan02, BitmapData2)
   if (E1 || E2)
      return -5

   x := y := 0
   if (Variation = 0)
   {
      E := DllCall(&_ImageSearch1, "uint", Scan01, "uint", Scan02, "int", hWidth, "int", hHeight, "int", nWidth, "int", nHeight, "int", Stride1
      , "int", Stride2, "int", sx, "int", sy, "int", w, "int", h, "int*", x, "int*", y)
   }
   else
   {
      E := DllCall(&_ImageSearch2, "uint", Scan01, "uint", Scan02, "int", hWidth, "int", hHeight, "int", nWidth, "int", nHeight, "int", Stride1
      , "int", Stride2, "int", sx, "int", sy, "int", w, "int", h, "int", Variation, "int*", x, "int*", y)
   }
   Gdip_UnlockBits(pBitmapHayStack, BitmapData1), Gdip_UnlockBits(pBitmapNeedle, BitmapData2)
   return E
}
It returns -3. Needle is definitely in haystack. Should I expect true, false, -1, 0?

I didn't put Gdip_ImageSearch2 anywhere as I don't know exactly what it is.

Thanks.

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Look through the function. The return values are clearly printed in the format of "return -N". The "return -3" line is under an If that checks if the images have widths and heights. It might mean your images aren't loading properly.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

GollyJer
  • Members
  • 24 posts
  • Last active: Dec 21 2012 06:35 PM
  • Joined: 15 Oct 2007
Frankie, my eyes had jumped to return E at the bottom of the code and I was asking about E:=DllCall. I now see the error codes in the code above. Thanks.

Messing around with some of the GDIP examples helped me realize I wasn't correctly starting up gdip. But, now that I have it correct, Gdip_ImageSearch only returns 0.

pToken := Gdip_Startup()

my_haystack := Gdip_CreateBitmapFromFile("Haystack.png")
my_needle := Gdip_CreateBitmapFromFile("Needle.png")
   
MsgBox % Gdip_ImageSearch(my_haystack, my_needle, FoundX, FoundY)

Gdip_ShutDown(pToken)
I even built a new simple two color haystack/needle and it's not working. :-|
To verify things seem to be passed in correctly I put this before return E in Gdip_ImageSearch and it returned the correct sizes.
MsgBox, % "Haystack: " hWidth " x " hHeight "`nNeedle: " nWidth " x " nHeight


tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007

But, now that I have it correct, Gdip_ImageSearch only returns 0.


Heh....0 means there was a match :wink:
Try MsgBoxing FoundX and FoundY in your example

To Check for a match you can do

if !Gdip_ImageSearch(pBitmapHayStack, pBitmapNeedle, x, y)
	MsgBox, %x%`n%y%