| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| confirmPermissionTag | string | 选填,默认值为'立即开始|允许' | confirmPermissionTag为权限对话框中确认打开权限的文字。如果不为空,则会自动点击该控件,自动确认打开权限;若为空则需要自己点击确认按钮。支持"|"分割多个文本,找到一个即可。 |
| retryCount | integer | 选填,默认值为5 | 点击confirmTag的重试次数 |
例子:
function main() {
requestScreenShot();
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| options | object | 选填,默认值{fileName:'', callback: null, destPath:'', region:[0, 0, 1, 1], quality: 0.8, imageType: 1} | fileName表示截图存放的文件名,为空时直接返回截图bitmap,默认存放的路径在手机扩展存储目录(一般为sdcard,注意不同的手机存储目录可能不同)下的aznfz目录下,支持png和jpg后缀。callback,回调函数,截图后的数据会传入该回调函数供进一步处理,回调函数返回值就是screenshot函数的返回值。destPath,图片存放的目标文件夹,相对手机扩展存储目录,注意不是绝对路径。region,截图区域,[left, top, width, height],若取值在[0, 1]之间表示比例,例:0.5表示left位于屏幕x轴中点;若取值大于1表示像素值。quality,图片质量取值范围0-100,默认值100。imageType,图片的类型,1表示png,2表示jpg,默认为1,注意:如果fileName的后缀带有文件类型(比如:xx.png)则以fileName为准。 |
例子:
function main() {
requestScreenShot();
var ret = screenShot({fileName: 'pic.png'});
console.log('ret:' + ret); // 为图片路径
// 直接返回位图时,在使用完后必须释放位图
// var bmp = screenShot();
// bmp.recycle();
// var ret = screenShot('', {callback: cbFun});
// console.log('ret:' + ret); //为true
}
function cbFun(bytes, bitmap) {
console.log('bytes:', bytes, ' bitmap:', bitmap);
return true;
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|
例子:
function main() {
stopScreenShot();
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| position | array | 必填 | 若数组里面item为两个整数则表示点的x,y坐标,单位像素值。,若数组里面item为数组,则用于同时获取多个点的颜色。例:单点:[x, y],多点:[[x1, y1],[x2,y2]] |
| bitmap | Bitmap | 选填 | 默认为null,如果为null则使用截屏后图片,否则直接使用该位图 |
例子:
function main() {
requestScreenShot();
// 返回单点的颜色,color为整数
var color = getScreenColor(200, 300);
console.log('color:' + color);
// 同时返回多个点的颜色,x为数组
var x = getScreenColor([[535, 292],[110, 256]])
console.log('x:' + x)
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| color | integer/string | 必填 | 颜色,支持整型值和字符串,字符串格式为#AARRGGBB或者#RRGGBB |
| options | object | 选填,默认值:{findAll:false, similarity: 0.9, bottom2top: false, region:[left, top, right, bottom], bitmap: null, neighbor:[[offsetX, offsetY, color], [offsetX, offsetY, color]]} | findAll表示是否查找所有符合条件的点。similarity表示颜色相似度,默认为0.95,1表示完全匹配,取值范围[0-1]。bottom2top,是否从底部向上找,默认false。region,可以在搜索时指定区域[left, top, right, bottom],注意:若取值在[0, 1]之间表示比例,例:[0.5, 100, 900, 2000]表示left位于屏幕x轴中点;若取值大于1表示像素值。neighbor表示对目标点的相邻点的颜色要求,偏移值为相对目标color坐标的偏移,可以为负值。bitmap, 默认为null,如果为null则使用截屏后图片,否则直接使用该位图。 |
例子:
function main() {
requestScreenShot();
// 注意,注意,注意:一定要去冰狐网站,移动端/我的设备/远程控制,然后用鼠标在界面上选择目标颜色和neighbor颜色,可以自动生成找色代码,非常方便。
// 比如我们想找图标,可以先在目标图标中选定一个其他地方没有的目标颜色(#445533),然后再在目标颜色周围选定比较有代表的颜色(最好是不同的颜色)作为neighbor参数,此时就可以高效,准确的找到目标位置了。
var arr = findColor('#445533', {similarity: 0.9, findAll: true, region:[10, 10, 300, 300], neighbor:[[0, 3, '#444455'],[3, 0, '#5673ff'],[-3, 10, '#ff3322'],[-9, 20, '#6ab322']]});
for(var point of arr) {
console.log('find color x:', point.x, ' y:', point.y);
}
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| colorArray | array | 必填 | [{color:'#ffssff', category:'a', value:0, neighbor:[[offsetX, offsetY, color], [offsetX, offsetY, color]]}]。color表示颜色值颜色,支持整型值和字符串,字符串格式为#AARRGGBB或者#RRGGBB。category表示类别,string类型,为了区分不同的颜色,会透传到结果中。value表示值,integer类型,给不同的类别配置一个值,会透传到结果中。neighbor表示对目标点的相邻点的颜色要求,偏移值为相对目标color坐标的偏移,可以为负值。 |
| options | object | 选填,默认值:{findAll:false, similarity: 0.9, bottom2top: false, rowFirst: true, region:[left, top, right, bottom], bitmap: null} | findAll表示是否查找所有符合条件的点, 默认false。similarity表示颜色相似度,默认为0.95,1表示完全匹配,取值范围[0-1]。bottom2top,是否从底部向上找,默认false。rowFirst,是否先遍历行,默认true。region,可以在搜索时指定区域[left, top, right, bottom],注意:若取值在[0, 1]之间表示比例,例:[0.5, 100, 900, 2000]表示left位于屏幕x轴中点;若取值大于1表示像素值。bitmap, 默认为null,如果为null则使用截屏后图片,否则直接使用该位图。 |
例子:
function main() {
requestScreenShot();
// 注意,注意,注意:一定要去冰狐网站,移动端/我的设备/远程控制,然后用鼠标在界面上选择目标颜色和neighbor颜色,可以自动生成找色代码,非常方便。
var ret = findColors([
{color:'#ff7b7d7b', category:'类1', value: 1, neighbor:[[0,3,'#ff7b7d7b'],[0,6,'#ff7b7d7b']]},
{color:'#ffd62829', category:'类2', value: 2, neighbor:[[0,3,'#ffd62829'],[0,6,'#ffd62829']]}
],{similarity: 0.9, region:[0, 0, 1, 1], bitmap: bmp});
for(var item of ret) {
console.log('find color x:', item.x, ' y:', item.y, ' category:', item.category, ' value:', item.value);
}
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| colors | array | 必填 | 这里为颜色数组,比如:[[12, 100, '#ff00cc'],[13, 102, 23456]],内部数组值依次表示x,y和目标颜色值,注意支持同时比较多个颜色值。颜色支持整型值和字符串,字符串格式为#AARRGGBB或者#RRGGBB |
| options | object | 选填,默认值:{similarity:0.9, bitmap: null} | similarity,颜色相似度,默认为0.9。取值范围[0, 1],1表示完全匹配。bitmap,默认为null,如果为null则使用截屏后图片,否则直接使用该位图。 |
例子:
function main() {
requestScreenShot();
// 注意,注意,注意:一定要去冰狐网站,移动端/我的设备/远程控制,然后用鼠标在界面上选择目标颜色,可以自动生成比较颜色的代码,非常方便。
if (compareColors([[45, 112, '#ff0055'], [44, 113, 345566]], {similarity:0.95})) {
console.log('颜色全部匹配');
}
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| imageFileName | string | 必填 | 图片名,注意:支持绝对路径、相对路径和asset文件,例:findImage('asset:template.png');(可以在定制App打包时将图片打包到app的asset中)。 |
| options | json object | 选填,默认值:{region:[0, 0, 1, 1], threshold: 0.85, bitmap: null, scale:{useScale:false, startScale:0.8, endScale:1.2, scaleStep: 0.1}}。 | region,识别区域[left, top, width, height],若取值在[0, 1]之间表示比例,例:0.5表示left位于屏幕x轴中点;若取值大于1表示像素值。默认值[0,0,1,1]。threshold,用于确定图片识别是否成功的阈值,取值范围[0, 1],默认值0.85,值越大则要求的匹配度越高。bitmap,默认为null,如果为null则使用截屏后图片,否则直接使用该位图。scale表示是否缩放图片,以便于适配不同的手机分辨率。 |
例子:
function main() {
requestScreenShot();
// 相对目录,Pictures目录下的图片
// var region = findImage('Pictures/template.jpg', {region:[10, 10, 300, 100]});
// 在apk资源目录中
// var region = findImage('asset:img.png', {region:[10, 10, 300, 100]});
// 绝对路径
var region = findImage('/sdcard/template.jpg');
if (region) {
console.log('find success x:', region.x, ' y:', region.y, ' width:', region.width, ' height:', region.height);
} else {
console.log('find image failed');
}
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| bitmap | Bitmap | 必填 | 位图 |
例子:
function main() {
requestScreenShot();
var bmp = screenShot();
var grayBmp = image2Gray(bmp)
var b = writeImage(grayBmp, '/sdcard/dd.png')
console.log('b:',b)
// 释放bitmap
bmp.recycle();
grayBmp.recycle();
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| bitmap | Bitmap | 必填 | 位图 |
| threshold | integer | 必填 | 阈值,取值范围0-255 |
例子:
function main() {
requestScreenShot();
var bmp = screenShot();
var destBmp = imageThreshold(bmp, 100)
var b = writeImage(destBmp, '/sdcard/dd.png')
console.log('b:',b)
// 释放bitmap
bmp.recycle();
destBmp.recycle();
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| path | string | 必填 | 图片路径,注意:支持绝对路径、相对路径 |
例子:
function main() {
var bitmap = readImage('/sdcard/template.jpg');
if (bitmap) {
console.log('find success:' + bitmap);
} else {
console.log('read failed');
}
// 释放bitmap
bitmap.recycle();
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| bitmap | Bitmap | 必填 | 位图 |
| path | string | 必填 | 目的图片的路径,注意:支持绝对路径、相对路径 |
| type | string | 选填 | 图片类型,支持'jpg'和'png',默认和path的后缀名一致 |
| quality | integer | 选填 | 图片质量0-100,默认为100 |
例子:
function main() {
var b = writeImage(bitmap, '/sdcard/template.jpg', 'jpg', 50);
console.log('b:' + b);
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| bitmap | Bitmap | 必填 | 位图 |
| left | integer | 必填 | left |
| top | integer | 必填 | top |
| width | integer | 必填 | width |
| height | integer | 必填 | height |
例子:
function main() {
var clipBmp = bitmapClip(bitmap, 100, 0, 200, 200);
// 释放bitmap
clipBmp.recycle();
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| bitmap | Bitmap | 必填 | 位图 |
例子:
function main() {
var bytes = bitmap2bytes(bitmap);
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| bytes | 字节数组 | 必填 | bytes |
例子:
function main() {
var bitmap = bytes2bitmap(bytes);
}
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| maxWaitTime | integer | 选填 | 最长等待多长时间设置完成,单位毫秒,默认值1000*40 |
例子:
var ret = requestLockScreen();
console.log('ret:' + ret);
| 参数名 | 类型 | 默认值 | 说明 |
|---|
例子: lockScreen();
| 参数名 | 类型 | 默认值 | 说明 |
|---|
例子: wakeup();