示例

## 获取网络图片并保存 ```js //这个是Auto.js图标的地址 var url = "https://www.autojs.org/assets/uploads/profile/3-profileavatar.png"; var logo = images.load(url); //保存到路径/sdcard/auto.js.png images.save(logo, "/sdcard/auto.js.png"); ``` ## 截图并保存 ```js if(!requestScreenCapture()){ toast("请求截图失败"); exit(); } var img = captureScreen(); images.saveImage(img, "/sdcard/1.png"); ``` ## 精确找色 ```js if(!requestScreenCapture()){ toast("请求截图失败"); stop(); } var img = captureScreen(); toastLog("开始找色"); //0x1d75b3为编辑器默认主题蓝色字体(if, var等关键字)的颜色 //找到颜色与0x1d75b3完全相等的颜色 var point = findColorEquals(img, 0x006699); if(point){ toastLog("x = " + point.x + ", y = " + point.y); }else{ toastLog("没有找到"); } ``` ## 模糊找色 ```js if(!requestScreenCapture()){ toast("请求截图失败"); exit(); } var img = captureScreen(); //0x9966ff为编辑器紫色字体的颜色 toastLog("开始找色"); var point = findColor(img, 0x9966ff); if(point){ toastLog("x = " + point.x + ", y = " + point.y); }else{ toastLog("没有找到"); } ``` ## 区域找色1 ```js if(!requestScreenCapture()){ toast("请求截图失败"); exit(); } var img = captureScreen(); toastLog("开始找色"); //指定在位置(100, 220)宽高为400*400的区域找色。 //#75438a是编辑器默认主题的棕红色字体(数字)颜色,位置大约在第5行的"2000",坐标大约为(283, 465) var point = findColorInRegion(img, "#75438a", 90, 220, 900, 1000); if(point){ toastLog("x = " + point.x + ", y = " + point.y); }else{ toastLog("没有找到"); } ``` ## 区域找色2 ```js if(!requestScreenCapture()){ toast("请求截图失败"); exit(); } var img = captureScreen(); //0xffffff为白色 toastLog("开始找色"); //指定在位置(90, 220)宽高为900*1000的区域找色。 //0xff00cc是编辑器的深粉红色字体(字符串)颜色 var point = findColor(img, "#ff00cc", { region: [90, 220, 900, 1000], threads: 8 }); if(point){ toastLog("x = " + point.x + ", y = " + point.y); }else{ toastLog("没有找到"); } ``` ## 实时显示触摸点颜色 ```js requestScreenCapture(); console.show(); events.observeTouch(); events.setTouchEventTimeout(30); events.on("touch", function(point){ var c = colors.toString(images.pixel(captureScreen(), point.x, point.y)); log("(" + point.x + ", " + point.y + "): " + c); }); ``` ## 图片处理 ```js "ui"; var url = "https://www.autojs.org/assets/uploads/files/1540386817060-918021-20160416200702191-185324559.jpg"; var logo = null; var currentImg = null; events.on("exit", function(){ if(logo != null){ logo.recycle(); } if(currentImg != null){ currentImg.recycle(); } }); ui.layout(