autojs 简单入门
首先
等待指定的应用出现。例如waitForPackage("com.tencent.mm")为等待当前界面为微信。
back()
powerDialog();
home()
notifications()
quickSettings()
recents()
splitScreen()
1、颜色的表示方法
#AARRGGBB
#RRGGBB
AA是A1pha通道(透明度)的值,
RR是R通道(红色)的值,
GG是G通道(绿色)的值,
BB是B通道(蓝色)的值
可以通过colors.toString()把颜色整数转换为字符串
通过colors.parseColor()把颜色字符串解析为颜色整数
2、颜色的转换方法
colors.toString(colorNum)
colors.red(Num|Str)
colors.green(Num|Str)
colors.blue(Num|Str)
colors.alpha(Num|Str)
colors.rgb(redNum,greenNum,blueNum)
colors.argb(alpha,red,green,blue)
colors.parsecolor(colorstr)
3、判断颜色是否相似或相等
colors.isSimilar(num|str,num|str[,thresholdNum,a1gorithm])
/返回两个颜色是否相等。*注意该函数会忽略Alpha通道的值进行比较。
colors.equals (num|str, num |str)
4、autojs内置颜色
colors.BLACK
黑色,颜色值 #FFO00000
colors.DKGRAY
深灰色,颜色值 #FF444444
colors.GRAY
灰色,颜色值 #FF888888
colors.LTGRAY
亮灰色,颜色值 #FFCCCCCC
colors.WHITE
白色,颜色值 #FFFFFFFF
colors.RED
红色,颜色值 #FFFF0000
colors.GREEN
绿色,颜色值 #FFOOFFO0
colors.BLUE
蓝色,颜色值 #FFO00OFF
colors.YELLOW
黄色,颜色值 #FFFFFF00
colors.CYAN
青色,颜色值 #FFOOFFFF
colors.MAGENTA
品红色,颜色值 #FFFFOOFF
colors.TRANSPARENT
透明,颜色值 #00000000
5、片回收机制(防内存泄露)
image对象创建后尽量在不使用时进行回收,同时避免循环创建大量图片。lmage对象通过调用recycle()函数来回收。
var img = images.read("./1.png"");
...
img.recycle();
例外的是,caputerScreen()返回的图片不需要回收。
6、读取图片
images.read(path)
images.load(ur1)
images.copy(img)
7、Image对象
Image.getWidth()
Image.getHeight()
Image.saveTo(path)
Image.pixe1(x,y)
8、图片对象的保存方法
Image.saveTo(path)
images.save(image,path[,format = "png", quality = 100])
9、图片的编码转换(base64和bytes)
images.fromBase64(base64)
images.toBase64(img[,format = "png",quality = 100])
images.fromBytes(bytes)
images.toBytes(img[,format = "png",quality = 100])
10、封装获取屏幕小图的函数
if(!requestScreenCapture()){
toast('请求截图失败');
exit();
}
sleep(3000);
toast('3')
function getImg(x1,y1,x2,y2,path){
var img = images.captureScreen();
var imgS = images.clip(img,x1,x2,x2-x1,y2-y1);
imgS.saveTo(path);
img.recycle();
toast('a')
}
getImg(100,100,200,200,'/sdcard/脚本/img.png')
11、图片处理的函数(非专业可以略过)
images.resize(img,size[,interpolation])
images.scale(img,fx,fy[,interpolation])
images.rotate(img,degress[,x,y])
images.concat(img1,image2[,direction])
images.grayscale(img)
image.threshold(img,threshold,maxVal[,type])
images.adaptiveThreshold(img,maxValue,adaptiveMethod,thresholdTrype, blockSize,C)
images.cvtColor(img,code[,dstCn])
images.inRange(img,lowerBound,upperBound)
images.interva1(img,color,interval)
images.blur(img,size[,anchor,type])
images.medianB1ur(img,size)
images.gaussianBlur(img,size[,sigmaX,sigmaY,type])
images.matToImage(mat)
12、请求截图权限
images.requestScreenCapture([landscape])
常用格式。
threads.start(function(){
while(true){
if(text('立即开始').findOnce()){
text('立即开始').findOnce().click();
break;
}else{
sleep(3000);
}
}
});
if(!requestScreenCapture()){
toast('请求截图失败');
exit();
}
13、截屏功能
images.captureScreen()
captureScreen()
区别:返回Image对象,保存到路径,不返回
images.captureScreen(path)
captureScreen(path)