add screen capture and color searching

This commit is contained in:
hyb1996
2017-05-22 15:41:11 +08:00
parent b3fad201f7
commit 302879333a
45 changed files with 1547 additions and 92 deletions

View File

@@ -0,0 +1,3 @@
### requestScreenCapture(\[width, height\])
* width \<Number\> 可选参数

View File

@@ -5,7 +5,8 @@ var dialogs = {};
dialogs.rawInput = function(title, prefill){
prefill = prefill || "";
return String(__runtime__.dialogs.rawInput(title, prefill));
var s = __runtime__.dialogs.rawInput(title, prefill);
return s ? String(s) : null;
};
dialogs.input = function(title, prefill){

View File

@@ -0,0 +1,17 @@
if(!requestScreenCapture()){
toast("请求截图失败");
stop();
}
var img = captureScreen();
//0xffffff为白色
toastLog("开始找色");
//指定在位置(90, 220)宽高为900*1000的区域找色。
//0xff00cc是编辑器的深粉红色字体(字符串)颜色
var point = findColorInRegion(img, 0xff00cc, 90, 220, 900, 1000);
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}

View File

@@ -0,0 +1,18 @@
if(!requestScreenCapture()){
toast("请求截图失败");
stop();
}
var img = captureScreen();
//0xffffff为白色
toastLog("开始找色");
//指定在位置(90, 220)宽高为900*1000的区域找色。
//0xff00cc是编辑器的深粉红色字体(字符串)颜色
var point = findColor(img, 0xff00cc, {
region: [90, 220, 900, 1000],
threads: 8
});
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}

View File

@@ -0,0 +1,19 @@
//减少截图分辨率以提高速度
if(!requestScreenCapture(640, 960)){
toast("请求截图失败");
stop();
}
var img = captureScreen();
toastLog("开始找色");
//0x02b902为输入法绿色字体的颜色
var point = findColor(img, 0x02b902, {
//指定用8个线程找色
threads: 8
});
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}

View File

@@ -0,0 +1,6 @@
if(!requestScreenCapture()){
toast("请求截图失败");
stop();
}
var img = captureScreen();
images.saveImage(img, "/sdcard/1.png");

View File

@@ -0,0 +1,6 @@
//指定截图分辨率为 640×960
if(!requestScreenCapture(640, 960)){
toast("请求截图失败");
stop();
}
captureScreen("/sdcard/1.png");

View File

@@ -0,0 +1,16 @@
if(!requestScreenCapture()){
toast("请求截图失败");
stop();
}
launchApp("QQ");
sleep(2000);
var img = captureScreen();
toastLog("开始找色");
var point = findColor(img, 0xf64d30);
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}

View File

@@ -0,0 +1,22 @@
if(!requestScreenCapture()){
toast("请求截图失败");
stop();
}
var img = captureScreen();
//0xffffff为白色
toastLog("开始找色");
var point = findColor(img, 0xffffff, {
//指定算法为rgb+,更默认算法rgb更准确,但时间更久
algorithm: "rgb+",
//指定颜色临界值为16
threshold: 16,
//指定用8个线程找色
threads: 8
});
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}

View File

@@ -0,0 +1,15 @@
if(!requestScreenCapture()){
toast("请求截图失败");
stop();
}
var img = captureScreen();
//0x9966ff为编辑器紫色字体的颜色
toastLog("开始找色");
var point = findColor(img, 0x9966ff);
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}

View File

@@ -0,0 +1,16 @@
if(!requestScreenCapture()){
toast("请求截图失败");
stop();
}
var img = captureScreen();
toastLog("开始找色");
//0x006699为编辑器蓝色字体(var)的颜色
//找到颜色与0x006699完全相等的颜色
var point = findColorEquals(img, 0x006699);
if(point){
toastLog("x = " + point.x + ", y = " + point.y);
}else{
toastLog("没有找到");
}