屏幕找图(screen.findImage)
函数
横坐标, 纵坐标 = screen.findImage(图片对象, [相似度 或 色偏值] ,{
colors = {
颜色值,
},
sim = 相似度或色偏值,
hitCount = 命中数,
mode = 黑白名单,
}, 是否匹配多个目标, [x, y, x1, y1])
参数
- 图片对象 必选
-
相似度 或 色偏值 可选 整数型
-
颜色过滤器 (版本:2.0.8 新增) 可选 数组型
-
colors 颜色值数组 必选 数组型
-
sim 颜色值数组中的 相似度或 色偏值 可选 整数型
-
hitCount 命中数, 此值越大找图速度 越慢 可选 整数型
-
mode 模式 默认 0 白名单模式 1 黑名单模式 可选 整数型
-
-
查找多个目标 find_all 可选 字符型
-
开始横坐标 可选 整数型
-
开始纵坐标 可选 整数型
1 - 结束横坐标 可选 整数型
- 结束纵坐标 可选 整数型
返回值
- 横坐标 整数型 失败返回 -1
-
纵坐标 整数型 失败返回 -1
-
结果列表 数组型 find_all 模式下
示例
--简单的示例 从屏幕创建图片对象
local img = screen.image(100,100,200,200) --随便截个图 用来测试找图
local x ,y = screen.findImage(img) --全屏找图
if x ~= -1 and y ~= -1 then
print(string.format("成功找到图片拉坐标: x= %d, y= %d" ,x ,y))
end
--另一个示例 从图片文件加载图片对象
local x ,y = screen.findImage(screen.loadImageFile("/var/mobile/Media/test.png") , 95)--全屏找图 相似度为 95
if x ~= -1 and y ~= -1 then
print(string.format("成功找到图片拉坐标: x= %d, y= %d" ,x ,y))
end
--另一个示例 从图片文件加载图片对象
local x ,y = screen.findImage(screen.loadImageFile("/var/mobile/Media/test.png") , 90, 100,100,400,600 ) --范围找图 相似度为 90
if x ~= -1 and y ~= -1 then
print(string.format("成功找到图片拉坐标: x= %d, y= %d" ,x ,y))
end
--另一个示例 从图片文件加载图片对象
local x ,y = screen.findImage(screen.loadImageFile("/var/mobile/Media/test.png") , 90, "find_all" ,100,100,400,600 ) --范围找图 相似度为 90 查找多个目标
if x ~= -1 and y ~= -1 then
print(string.format("成功找到图片拉坐标: x= %d, y= %d" ,x ,y))
end
--查找某音 点赞按钮例子
local imgPath = "/var/mobile/Media/svip/res/aixing.png"
local x, y = screen.findImage(screen.loadImageFile(imgPath), 0x202020 ,{
colors ={
0xFF284C
},
sim = 0x101010, --colors 数组中的颜色值 色偏 支持 模糊度模式下 0-100 色偏模式下 0x000000-0xFFFFFF
hitCount = 10, --允许未命中数量
mode = 0, -- 模式 0 白名单模式 1 黑名单模式
} ,717, 862, 817, 1406)