| 
 | 
 
 
图色找图的完整脚本 
- // 启动截图功能
 
 - if (!requestScreenCapture()) {
 
 -     toast("请求截图失败");
 
 -     exit();
 
 - }
 
  
- // 找图函数
 
 - function findImageOnScreen(targetImagePath, threshold) {
 
 -     threshold = threshold || 0.8; // 设置匹配阈值,默认 0.8
 
 -     let screenshot = captureScreen(); // 截取当前屏幕
 
 -     let targetImage = images.read(targetImagePath); // 读取目标图片
 
  
-     if (!targetImage) {
 
 -         toast("无法加载目标图片: " + targetImagePath);
 
 -         return null;
 
 -     }
 
  
-     // 在截图中寻找目标图片
 
 -     let match = images.findImage(screenshot, targetImage, {
 
 -         threshold: threshold
 
 -     });
 
  
-     // 释放图片资源
 
 -     targetImage.recycle();
 
 -     screenshot.recycle();
 
  
-     // 返回匹配结果
 
 -     return match;
 
 - }
 
  
- // 模拟点击匹配到的图片位置
 
 - function clickImage(targetImagePath, threshold) {
 
 -     let result = findImageOnScreen(targetImagePath, threshold);
 
 -     if (result) {
 
 -         toast("找到目标图片,点击位置: (" + result.x + ", " + result.y + ")");
 
 -         click(result.x + result.width / 2, result.y + result.height / 2); // 点击图片中心
 
 -     } else {
 
 -         toast("未找到目标图片");
 
 -     }
 
 - }
 
  
- // 示例用法
 
 - let imagePath = "/sdcard/target.png"; // 替换为目标图片的路径
 
 - clickImage(imagePath, 0.85); // 调用函数,阈值为 0.85
 
 
  复制代码 
 
 
 
 |   
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
×
 
 
 
 
 |