这一期带来的是遍历图片在屏幕上出现的所有坐标脚本源码。来源于郭立员作者分享。
适用范围:
同一个图片在屏幕上出现多次,如下图所示:
上面这些图都比较简单, 要找的图片都在一列上,而我们这期代码不局限于这种,而是全屏任意排列,保证无遗漏查找。
使用方法:
①使用抓抓截取你要找的图片
②查看截图的大小尺寸,填入到代码的第一部分(这部分也可以使用命令获取图片大小)
③把图片上传到脚本附件,修改脚本中的1.png和你的截图名称一致。
④确定找图范围,如果是全屏找图,无需修改,如果是指定找图范围,需要修改sx1,sy1,sx2,sy2这几个变量。
⑤代码执行完得到的是所有的坐标,并且存入到数组变量arr中,如果需要使用坐标操作,可以通过变量数组获取坐标。
⑥对于仅需要点击坐标的情况,可以不用存入数组,直接在找图里面用
tap intx,inty
脚本源码:
'定义截图的大小
Dim x=18
Dim y=20
'获取屏幕大小,如果指定范围,直接填写数值
Dim sx1=0
Dim sy1=0
Dim sx2=GetScreenX()
Dim sy2=GetScreenY()
'定义存储坐标的数组变量
Dim arr(),n=0
'遍历图片
Dim intx,inty
KeepCapture
For j = 0 To cint((sy2-sy1)/y)
For i = 0 To CInt((sx2 - sx1) / x)
FindPic sx1+x*i, sy1+y*j, sx1+2*x-1+x*i, sy1+2*y-1+y*j, "Attachment:1.png","000000", 0, 0.9, intX, intY
If intX > -1 And intY > -1 Then
arr(n) = intx & "," & inty
n=n+1
End If
Next
Next
ReleaseCapture
TracePrint join(arr,"|")
一图多坐标
Dim img,startx,starty,endx,endy,count
Dim intX, intY
img = "Attachment:1.png"'改成自己图片名称
startx = 1 : starty = 1 : endx = 720 : endy = 1028 : count = 0'前4参数改成自己分辨率
Do
FindPic startx, starty, endx, endy, img, "000000", 0, 0.9, intX, intY
If intx = - 1 Then
If startx=0 Then Exit do //查找结束
starty = starty + 1 : startx = 0
Else
If inty = starty or startx = 0 Then
startx = intx + 1:starty=inty
count = count + 1
TracePrint intX, intY
Else
startx = 0 : starty = starty + 1
End If
End If
Loop
********************
一字多坐标
TracePrint SetDictEx(0, "Attachment:123.txt")
TracePrint UseDict(0)
//以上两句脚本只需要调用一次
Dim img,startx,starty,endx,endy,count
Dim intX, intY
img = "安装"'改成自己文字
startx = 1 : starty = 1 : endx = 1028: endy = 720 : count = 0'前4参数改成自己分辨率
Do
FindStr(startx, starty, endx, endy,img,"A0A0A0-303030",0.8,intX,intY)
If intx = - 1 Then
If startx=0 Then Exit do //查找结束
starty = starty + 1 : startx = 0
Else
If inty = starty or startx = 0 Then
startx = intx + 1:starty=inty
count = count + 1
TracePrint intX, intY
Else
startx = 0 : starty = starty + 1
End If
End If
Loop