Auto.js 踩坑日记

  • 细节1

    click('扫一扫')click(x, y),后者只会在 基于坐标 的环境下生效,默认不是。

    // 必现要在前面设置屏幕宽高
    setScreenMetrics(1600, 900);
    // 点击指定坐标才会生效,否则只能按控件的点击事件进行生效
    click(point.x, point.y)
    
  • 错误1

    Can't find method com.stardust.autojs.core.image.ColorFinder.findMultiColors(boolean,number,number,org.opencv.core.Rect,[I)
    

    原因是:使用了截图函数,并传入了保存地址,截图函数传入保存地址后则不会返回 images 对象。

    var img = captureScreen("/sdcard/screencapture.png");
    var point = findMultiColors(img, "#123456", [[10, 20, "#ffffff"], [30, 40, "#000000"]], {
          
          
      region: [0, 960, 1080, 960]
    });
    if(point){
          
          
      toast("找到了");
    } else {
          
          
      toast('未找到');
    }
    

    改为一下即可,如果一定要存储,可以改为存储后,再读取出来使用图片

    var img = captureScreen();
    var point = findMultiColors(img, "#123456", [[10, 20, "#ffffff"], [30, 40, "#000000"]], {
          
          
      region: [0, 960, 1080, 960]
    });
    if(point){
          
          
      toast("找到了");
    } else {
          
          
      toast('未找到');
    }
    
  • 错误2

    Error: out of region: region = [1092,100,113,144], image.size = [900,1600]
    

    原因是:查找的图色坐标超过了,尤其是使用图色查找助手的需要注意,图色助手的值可能没问题,但是代码中的截图可能有问题,因为横竖屏截图尺寸不一样,截出图的自然就没法进行对比。

    requestScreenCapture(false);
    var img = captureScreen();
    // 确认一下尺寸,尤其是ipad上,会存在尺寸相反的问题
    console.log(img.getWidth(), img.getHeight());
    
  • 后续再补充…

猜你喜欢

转载自blog.csdn.net/zz00008888/article/details/141365498