mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
docs
This commit is contained in:
parent
f83b2fb923
commit
d1221d530e
@ -8,8 +8,8 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 244
|
||||
versionName "3.0.0 Alpha44"
|
||||
versionCode 245
|
||||
versionName "3.0.0 Alpha45"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
|
||||
@ -84,6 +84,7 @@
|
||||
<li><span class="stability_undefined"><a href="#images_images_findcolor_image_color_options">images.findColor(image, color, options)</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#images_images_findcolorinregion_img_color_x_y_width_height_threshold">images.findColorInRegion(img, color, x, y[, width, height, threshold])</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#images_images_findcolorequals_img_color_x_y_width_height">images.findColorEquals(img, color[, x, y, width, height])</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#images_images_findmulticolors_img_firstcolor_colors_options">images.findMultiColors(img, firstColor, colors[, options])</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#images_images_detectscolor_image_color_x_y_threshold_16_algorithm_diff">images.detectsColor(image, color, x, y[, threshold = 16, algorithm = "diff"])</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#images_images_findimage_img_template_options">images.findImage(img, template[, options])</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#images_images_findimageinregion_img_template_x_y_width_height_threshold">images.findImageInRegion(img, template, x, y[, width, height, threshold])</a></span></li>
|
||||
@ -210,7 +211,7 @@ images.save(clip, "/sdcard/clip.png");
|
||||
<p>选项包括:</p>
|
||||
<ul>
|
||||
<li><code>region</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type"><Array></a> 找色区域。是一个两个或四个元素的数组。(region[0], region[1])表示找色区域的左上角;region[2]*region[3]表示找色区域的宽高。如果只有region只有两个元素,则找色区域为(region[0], region[1])到屏幕右下角。如果不指定region选项,则找色区域为整张图片。</li>
|
||||
<li><code>threshold</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> 找色时颜色相似度的临界值,范围为0~255(越小越相似,0为颜色相等,255为任何颜色都能匹配)。默认为16。threshold和浮点数相似度(0.0~1.0)的换算为 similarity = (255 - threshold) / 255.</li>
|
||||
<li><code>threshold</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> 找色时颜色相似度的临界值,范围为0~255(越小越相似,0为颜色相等,255为任何颜色都能匹配)。默认为4。threshold和浮点数相似度(0.0~1.0)的换算为 similarity = (255 - threshold) / 255.</li>
|
||||
</ul>
|
||||
<p>该函数也可以作为全局函数使用。</p>
|
||||
<p>一个循环找色的例子如下:</p>
|
||||
@ -274,6 +275,28 @@ if(p){
|
||||
}else{
|
||||
toast("没有未读消息");
|
||||
}
|
||||
</code></pre><h2>images.findMultiColors(img, firstColor, colors[, options])<span><a class="mark" href="#images_images_findmulticolors_img_firstcolor_colors_options" id="images_images_findmulticolors_img_firstcolor_colors_options">#</a></span></h2>
|
||||
<div class="signature"><ul>
|
||||
<li><code>img</code> <span class="type"><Image></span> 要找色的图片</li>
|
||||
<li><code>firstColor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> 第一个点的颜色</li>
|
||||
<li><code>colors</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type"><Array></a> 表示剩下的点相对于第一个点的位置和颜色的数组,数组的每个元素为[x, y, color]</li>
|
||||
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 选项,包括:<ul>
|
||||
<li><code>region</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type"><Array></a> 找色区域。是一个两个或四个元素的数组。(region[0], region[1])表示找色区域的左上角;region[2]*region[3]表示找色区域的宽高。如果只有region只有两个元素,则找色区域为(region[0], region[1])到屏幕右下角。如果不指定region选项,则找色区域为整张图片。</li>
|
||||
<li><code>threshold</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> 找色时颜色相似度的临界值,范围为0~255(越小越相似,0为颜色相等,255为任何颜色都能匹配)。默认为4。threshold和浮点数相似度(0.0~1.0)的换算为 similarity = (255 - threshold) / 255.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div><p>多点找色,类似于按键精灵的多点找色,其过程如下:</p>
|
||||
<ol>
|
||||
<li>在图片img中找到颜色firstColor的位置(x0, y0)</li>
|
||||
<li>对于数组colors的每个元素[x, y, color],检查图片img在位置(x + x0, y + y0)上的像素是否是颜色color,是的话返回(x0, y0),否则继续寻找firstColor的位置,重新执行第1步</li>
|
||||
<li>整张图片都找不到时返回<code>null</code></li>
|
||||
</ol>
|
||||
<p>例如,对于代码<code>images.findMultiColors(img, "#123456", [[10, 20, "#ffffff"], [30, 40, "#000000"]])</code>,假设图片在(100, 200)的位置的颜色为#123456, 这时如果(110, 220)的位置的颜色为#fffff且(130, 240)的位置的颜色为#000000,则函数返回点(100, 200)。</p>
|
||||
<p>如果要指定找色区域,则在options中指定,例如:</p>
|
||||
<pre><code>var p = images.findMultiColors(img, "#123456", [[10, 20, "#ffffff"], [30, 40, "#000000"]], {
|
||||
region: [0, 960, 1080, 960]
|
||||
});
|
||||
</code></pre><h2>images.detectsColor(image, color, x, y[, threshold = 16, algorithm = "diff"])<span><a class="mark" href="#images_images_detectscolor_image_color_x_y_threshold_16_algorithm_diff" id="images_images_detectscolor_image_color_x_y_threshold_16_algorithm_diff">#</a></span></h2>
|
||||
<div class="signature"><ul>
|
||||
<li><code>image</code> <span class="type"><Image></span> 图片</li>
|
||||
|
||||
@ -75,6 +75,7 @@
|
||||
<li><span class="stability_undefined"><a href="#qa_q_a">Q & A</a></span><ul>
|
||||
<li><span class="stability_undefined"><a href="#qa">如何定时运行脚本</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#qa_1">如何把图片和脚本一起打包,或者打包多个脚本</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#qa_2">如何使打包的应用不显示主界面</a></span></li>
|
||||
<li><span class="stability_undefined"><a href="#qa_auto_js">Auto.js自带的模块和函数中没有的功能如何实现</a></span></li>
|
||||
</ul>
|
||||
</li>
|
||||
@ -96,6 +97,25 @@
|
||||
</ol>
|
||||
<p>例如,主脚本要读取同一文件夹下的图片1.png,再执行找图,则可以通过<code>images.read("./1.png")</code>来读取,其中"./1.png"表示同一目录1.png图片;ui中的图片控件要引用同一文件夹的2.png图片则为<code><img src="file://2.png"/></code>。Auto.js内置的函数和模块都支持相对路径,但是,其他情况则需要使用<code>files.path()</code>函数来把相对路径转换为绝对路径。</p>
|
||||
<p>目前Auto.js还不支持项目的图形化管理,后续会加入。</p>
|
||||
<h2>如何使打包的应用不显示主界面<span><a class="mark" href="#qa_2" id="qa_2">#</a></span></h2>
|
||||
<p>需要使用项目打包功能。</p>
|
||||
<ol>
|
||||
<li>新建一个文件夹,命名为项目名称。</li>
|
||||
<li>在该文件夹下新建脚本,或者移动脚本到该文件夹,命名为main.js,表示主脚本。脚本打包后将会从该脚本开始运行。</li>
|
||||
<li>在该文件夹下新建一个project.json的文件,其内容如下:<pre><code>{
|
||||
"name": "项目名称",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": 1,
|
||||
"packageName": "org.autojs.example",
|
||||
"main": "main.js",
|
||||
"launchConfig": {
|
||||
"hideLogs": true
|
||||
}
|
||||
}
|
||||
</code></pre>其中,项目名称改为自己的项目名称,"org.autojs.example"改成自己的包名,下面的"launchConfig"表示启动配置,"hideLogs"表示隐藏日志。</li>
|
||||
<li>通过文件夹菜单的"打包"功能来打包该项目</li>
|
||||
</ol>
|
||||
<p>有关项目打包和配置的更多信息,参见项目与项目配置(待补)。</p>
|
||||
<h2>Auto.js自带的模块和函数中没有的功能如何实现<span><a class="mark" href="#qa_auto_js" id="qa_auto_js">#</a></span></h2>
|
||||
<p>由于Auto.js支持直接调用Android的API,对于Auto.js没有内置的函数,可以直接通过修改Android代码为JavaScript代码实现。例如旋转图片的Android代码为:</p>
|
||||
<pre><code>import android.graphics.Bitmap;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user