i just wanted to share that code with all the forum
its my first function and i wanted you to tell me your opinion
thanks
;==============================[General]=================================
;ImageCompare is an ahk function created with ImageSearch.
;It can be used to check if two images are visible in an area of your choise.
;
;==========================[Build the function]========================
;
;The function can be formed as:
;ImageCompare("imagefile1",'imagefile2",dx,dy,(errors:=0) )
;
;-----------------------------------------------------------------------------------------------------------------------------------------
;imagefile1=The image file that script is firstly searching for
;
;imagefile2=The image that you want to find in an area,around imagefile1
;
;dx=the amount of 'x' pixels around imagefile1('x' coordinates of search area)
;
;dy=the amount of 'y' pixels around imagefile1('y' coordinates of search area)
;
;errors:
;
;0: Image1 appears next to image2 <---When you call the function it MUST be :=0
;1: Image1 does not exists next to image2
;2: Cant locate at least one of the image files
;
;NOTE: If you want to find an image that appears in an area of 30 pixels around imagefile1,then:
; dx=dy=30.Its not calcuated as coordinateX=dx/2 (Supposing that imagefile1 is in the
; middle of 30 pixels )
;=============================[Tips]============================================
;1)Try use dx and dy depending on the size of images you are working with
;2)Use .png files.JPG lacks of quality
;=========================[ImageCompare.ahk]=====================================
ImageCompare(byref imagefile1,byref imagefile2,byref dx,byref dy,byref errors)
{
;==Default settings|Please dont edit==
errors := 1
CoordMode,Mouse,Screen
CoordMode,Pixel,Screen
;==End default settings==
;Searching for first image (imagefile1)
ImageSearch , FoundX , FoundY , 0 , 0 , A_Screenwidth , A_screenheight , %imagefile1%.png
if errorlevel = 1
{
errors := 2 ; Image1 couldnt be found
return errors
}
else if errorlevel = 2
Magbox , Error at process
;If imagefile1 exists,searches for imagefile2
else
{
sleep 1000
click %FoundX%,%FoundY% ; clicks imagefile1.In case you dont want to click it,just add ';' in front of this line
sleep 1000
; Calculating the area around imagefile1
foundxx := foundx - dx ; -dx pixels left from imagefile1
foundyy := foundy - dy ; -dy pixels up from imagefile1
foundplusxx := foundx + dx ; +dx pixels right from imagefile1
foundplusyy := foundy + dy ; +dy pixels down from imagefile1
Imagesearch ,FoundX2,FoundY2,%foundxx%,%foundyy%,%foundplusxx%,%foundplusyy%, %imagefile2%.png
if errorlevel = 0
{
traytip,,%imagefile2% is next to %imagefile1%
errors := 0
}
else if errorlevel = 1
{
errors := 1 ; Image2 does not exist at the selected area,around image1
return errors
}
else
{
errors := 2 ; Image2 couldnt be found
return errors
}
}
return errors
}




