Appearance
图片模块(image)
image 模块约定
找色 / 找图:区域四元组在前,如
findPic(0, 0, 1080, 1920, 'btn.bmp', 0.9)。模板放在template/或脚本同目录,按文件名读取。找图为逐像素比较(sim控制颜色容差)。单点接口返回首个命中或null,*Ex返回数组。颜色推荐#RRGGBB-#tol。多点找色points为[{ dx, dy, color }, ...]。无默认值,参数均必填。
最短示例:
javascript
reg('YOUR_KEY');
let p = image.findPic(0, 0, 1080, 1920, 'btn.bmp', 0.9);
if (p) auto.click(p.centerX, p.centerY);
const c = image.findColor(0, 0, 1080, 1920, '#FF0000-#101010', 0.9, 0);
if (c) auto.click(c.x, c.y);image.capture - 截图
typescript
function image.capture(): Promise<imageId | null>;
function image.capture(x1, y1, x2, y2): Promise<imageId | null>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| (无参) | - | - | - | 全屏截图 |
| x1,y1,x2,y2 | number | 区域时必填 | - | 矩形区域(物理像素) |
返回值:
| 类型 | 描述 |
|---|---|
| `Promise<imageId | null>` |
示例:
javascript
let id = image.capture();
const part = image.capture(0, 0, 200, 200);image.findColor - 找色(首个命中)
typescript
function image.findColor(x1, y1, x2, y2, color, sim, dir): Promise<{x,y}|null>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| x1, y1, x2, y2 | number | 是 | - | 查找区域(物理像素) |
| color | string | 是 | - | 如 #FFFFFF-#202020;多色用 ` |
| sim | number | 是 | - | 相似度 0~1 |
| dir | number | 是 | - | 查找方向:0 左→右/上→下;1 左→右/下→上;2 右→左/上→下;3 右→左/下→上 |
返回字段:
| 字段 | 类型 | 描述 |
|---|---|---|
| x, y | number | 命中点物理像素;未找到返回 null |
示例:
javascript
let p = image.findColor(0, 0, 1080, 1920, '#00FF00-#101010', 0.92, 0);
if (p) auto.click(p.x, p.y);image.findColorEx - 找色(全部命中)
typescript
function image.findColorEx(x1, y1, x2, y2, color, sim, dir, limit): Promise<{x,y}[]>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| x1, y1, x2, y2 | number | 是 | - | 查找区域(物理像素) |
| color | string | 是 | - | 如 #FFFFFF-#202020;多色用 ` |
| sim | number | 是 | - | 相似度 0~1 |
| dir | number | 是 | - | 查找方向:0 左→右/上→下;1 左→右/下→上;2 右→左/上→下;3 右→左/下→上 |
| limit | number | 是 | - | 最多命中数 |
返回值:
| 类型 | 描述 |
|---|---|
Promise<{x,y}[]> | 全部命中点;无则为空数组 |
示例:
javascript
let hits = image.findColorEx(0, 0, 500, 800, '#FFFFFF-#20', 0.9, 0, 10);
logger.debug('命中数', hits.length);image.findMultiColor - 多点找色(首个命中)
typescript
function image.findMultiColor(x1, y1, x2, y2, firstColor, points, sim, dir): Promise<{x,y}|null>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| x1, y1, x2, y2 | number | 是 | - | 查找区域(物理像素) |
| firstColor | string | 是 | - | 首色 |
| points | Array<{dx,dy,color}> | 是 | - | 相对偏移点列表 |
| sim | number | 是 | - | 相似度 |
| dir | number | 是 | - | 查找方向:0 左→右/上→下;1 左→右/下→上;2 右→左/上→下;3 右→左/下→上 |
示例:
javascript
let p = image.findMultiColor(0, 0, 1080, 1920, '#FF0000-#10', [
{ dx: 10, dy: 0, color: '#00FF00-#10' },
{ dx: 0, dy: 10, color: '#0000FF-#10' },
], 0.9, 0);image.findMultiColorEx - 多点找色(全部命中)
typescript
function image.findMultiColorEx(x1, y1, x2, y2, firstColor, points, sim, dir, limit): Promise<{x,y}[]>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| x1, y1, x2, y2 | number | 是 | - | 查找区域(物理像素) |
| firstColor | string | 是 | - | 首色 |
| points | Array<{dx,dy,color}> | 是 | - | 相对偏移点列表 |
| sim | number | 是 | - | 相似度 |
| dir | number | 是 | - | 查找方向:0 左→右/上→下;1 左→右/下→上;2 右→左/上→下;3 右→左/下→上 |
| limit | number | 是 | - | 最多命中数 |
示例:
javascript
let hits = image.findMultiColorEx(0, 0, 1080, 1920, '#FF0000-#10', [
{ dx: 10, dy: 0, color: '#00FF00-#10' },
], 0.9, 0, 10);image.findPic - 找图(首个命中)
typescript
function image.findPic(x1, y1, x2, y2, pic, sim): Promise<FindHit|null>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| x1, y1, x2, y2 | number | 是 | - | 查找区域(物理像素) |
| pic | string | 是 | - | 模板路径或内存 imageId(推荐 BMP) |
| sim | number | 是 | - | 相似度;逐像素比较,1=精确,0.9≈每通道容差 25 |
返回字段(FindHit):
| 字段 | 类型 | 描述 |
|---|---|---|
| x, y | number | 左上角 |
| ex, ey | number | 右下角 |
| width, height | number | 宽高 |
| centerX, centerY | number | 中心(常用于点击) |
| confidence | number | 匹配度 |
示例:
javascript
let p = image.findPic(0, 0, 1080, 1920, 'btn.bmp', 0.9);
if (p) auto.click(p.centerX, p.centerY);image.findPicEx - 找图(全部命中)
typescript
function image.findPicEx(x1, y1, x2, y2, pic, sim, limit): Promise<FindHit[]>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| x1, y1, x2, y2 | number | 是 | - | 查找区域(物理像素) |
| pic | string | 是 | - | 模板路径或内存 imageId(推荐 BMP) |
| sim | number | 是 | - | 相似度;逐像素比较,1=精确,0.9≈每通道容差 25 |
| limit | number | 是 | - | 最多命中数 |
返回值:
| 类型 | 描述 |
|---|---|
Promise<FindHit[]> | 全部命中;无则为空数组(字段同 findPic) |
示例:
javascript
let all = image.findPicEx(0, 0, 500, 800, 'icon.bmp', 0.85, 10);
logger.debug('命中数', all.length);image.cmpColor - 比色
typescript
function image.cmpColor(x, y, color, sim): Promise<boolean>;
function image.cmpColor(points, sim): Promise<boolean>;参数说明:
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| x,y,color | - | 单点形式 | - | 单点比色 |
| points | Array<{x,y,color}> | 多点形式 | - | 全部匹配才为 true |
示例:
javascript
let ok = image.cmpColor(100, 200, '#FF0000-#10', 0.9);image.readImage / saveTo / release / getSize / pixel / argb
typescript
readImage(path) → imageId
saveTo(imageId, filePath) → boolean
release(imageId) / releaseAll()
getSize(imageId) → {width,height}
pixel(imageId, x, y) → number
argb(color) → string示例:
javascript
let id = image.readImage('tpl.png');
const sz = image.getSize(id);
image.release(id);