|
|
|
@ -3,10 +3,10 @@ package com.example.jmacro.wjdr;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import cn.hutool.core.util.ReUtil;
|
|
|
|
|
import com.example.jmacro.wjdr.base.ScreenPoint;
|
|
|
|
|
import com.example.jmacro.wjdr.base.ScreenRect;
|
|
|
|
|
import com.example.jmacro.wjdr.base.ViewPoint;
|
|
|
|
|
import com.example.jmacro.wjdr.base.ViewRect;
|
|
|
|
|
import com.example.jmacro.wjdr.util.ColorUtil;
|
|
|
|
|
import com.example.jmacro.wjdr.util.Imager;
|
|
|
|
|
import com.example.jmacro.wjdr.util.ImageUtil;
|
|
|
|
|
import com.example.jmacro.wjdr.util.Logger;
|
|
|
|
|
import com.example.jmacro.wjdr.util.TaskUtil;
|
|
|
|
|
|
|
|
|
@ -17,7 +17,7 @@ import java.io.File;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Java脚本精灵
|
|
|
|
|
* 脚本
|
|
|
|
|
*
|
|
|
|
|
* @author wangbing
|
|
|
|
|
* @version 0.0.1
|
|
|
|
@ -35,11 +35,15 @@ public class JMacro {
|
|
|
|
|
*/
|
|
|
|
|
private File legend;
|
|
|
|
|
|
|
|
|
|
public JMacro() throws AWTException {
|
|
|
|
|
// 机器人初始化
|
|
|
|
|
this.robot = new Robot();
|
|
|
|
|
this.robot.setAutoDelay(100);
|
|
|
|
|
this.legend = new File("legend");
|
|
|
|
|
public JMacro() {
|
|
|
|
|
try {
|
|
|
|
|
// 机器人初始化
|
|
|
|
|
this.robot = new Robot();
|
|
|
|
|
this.robot.setAutoDelay(100);
|
|
|
|
|
this.legend = new File("legend");
|
|
|
|
|
} catch (AWTException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JMacro(File legend) throws AWTException {
|
|
|
|
@ -77,7 +81,7 @@ public class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param point 坐标点
|
|
|
|
|
*/
|
|
|
|
|
public void mouseMove(ScreenPoint point) {
|
|
|
|
|
public void mouseMove(ViewPoint point) {
|
|
|
|
|
mouseMove(point, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -87,7 +91,7 @@ public class JMacro {
|
|
|
|
|
* @param point 坐标点
|
|
|
|
|
* @param smooth 平滑移动
|
|
|
|
|
*/
|
|
|
|
|
public void mouseMove(ScreenPoint point, boolean smooth) {
|
|
|
|
|
public void mouseMove(ViewPoint point, boolean smooth) {
|
|
|
|
|
if (smooth) {
|
|
|
|
|
// 获取当前鼠标位置
|
|
|
|
|
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
|
|
|
|
@ -120,7 +124,7 @@ public class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param rect 点
|
|
|
|
|
*/
|
|
|
|
|
public void mouseLeftClick(ScreenPoint rect) {
|
|
|
|
|
public void mouseLeftClick(ViewPoint rect) {
|
|
|
|
|
mouseMove(rect);
|
|
|
|
|
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
|
|
|
|
delayTap();
|
|
|
|
@ -132,8 +136,8 @@ public class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param rect 矩形区域
|
|
|
|
|
*/
|
|
|
|
|
public void mouseLeftClick(ScreenRect rect) {
|
|
|
|
|
mouseLeftClick(new ScreenPoint(rect.getCenter()[0], rect.getCenter()[1]));
|
|
|
|
|
public void mouseLeftClick(ViewRect rect) {
|
|
|
|
|
mouseLeftClick(new ViewPoint(rect.getCenter()[0], rect.getCenter()[1]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -142,7 +146,7 @@ public class JMacro {
|
|
|
|
|
* @param start 开始位置
|
|
|
|
|
* @param end 结束位置
|
|
|
|
|
*/
|
|
|
|
|
public void mouseLeftDrag(ScreenPoint start, ScreenPoint end) {
|
|
|
|
|
public void mouseLeftDrag(ViewPoint start, ViewPoint end) {
|
|
|
|
|
mouseLeftDrag(start, end, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -153,7 +157,7 @@ public class JMacro {
|
|
|
|
|
* @param end 结束位置
|
|
|
|
|
* @param smooth 平滑移动
|
|
|
|
|
*/
|
|
|
|
|
public void mouseLeftDrag(ScreenPoint start, ScreenPoint end, boolean smooth) {
|
|
|
|
|
public void mouseLeftDrag(ViewPoint start, ViewPoint end, boolean smooth) {
|
|
|
|
|
mouseMove(start, smooth);
|
|
|
|
|
delayTap();
|
|
|
|
|
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
|
|
|
@ -169,7 +173,7 @@ public class JMacro {
|
|
|
|
|
* @param start 开始位置
|
|
|
|
|
* @param end 结束位置
|
|
|
|
|
*/
|
|
|
|
|
public void mouseRightDrag(ScreenPoint start, ScreenPoint end) {
|
|
|
|
|
public void mouseRightDrag(ViewPoint start, ViewPoint end) {
|
|
|
|
|
mouseRightDrag(start, end, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -180,7 +184,7 @@ public class JMacro {
|
|
|
|
|
* @param end 结束位置
|
|
|
|
|
* @param smooth 平滑移动
|
|
|
|
|
*/
|
|
|
|
|
public void mouseRightDrag(ScreenPoint start, ScreenPoint end, boolean smooth) {
|
|
|
|
|
public void mouseRightDrag(ViewPoint start, ViewPoint end, boolean smooth) {
|
|
|
|
|
mouseMove(start, smooth);
|
|
|
|
|
delayTap();
|
|
|
|
|
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
|
|
|
|
@ -195,7 +199,7 @@ public class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param rect 矩形区域
|
|
|
|
|
*/
|
|
|
|
|
public void mouseWheelClick(ScreenRect rect) {
|
|
|
|
|
public void mouseWheelClick(ViewRect rect) {
|
|
|
|
|
delayTap();
|
|
|
|
|
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
|
|
|
|
|
delayTap();
|
|
|
|
@ -209,7 +213,7 @@ public class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param rect 矩形区域
|
|
|
|
|
*/
|
|
|
|
|
public void mouseRightClick(ScreenRect rect) {
|
|
|
|
|
public void mouseRightClick(ViewRect rect) {
|
|
|
|
|
delayTap();
|
|
|
|
|
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
|
|
|
|
|
delayTap();
|
|
|
|
@ -223,7 +227,7 @@ public class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param rect 矩形区域
|
|
|
|
|
*/
|
|
|
|
|
public void mouseLeftDoubleClick(ScreenRect rect) {
|
|
|
|
|
public void mouseLeftDoubleClick(ViewRect rect) {
|
|
|
|
|
delayTap();
|
|
|
|
|
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
|
|
|
|
|
delayTap();
|
|
|
|
@ -239,16 +243,16 @@ public class JMacro {
|
|
|
|
|
/**
|
|
|
|
|
* 捕获指定区域屏幕
|
|
|
|
|
*/
|
|
|
|
|
public BufferedImage capture(Robot robot, ScreenRect screenRect) {
|
|
|
|
|
return robot.createScreenCapture(new Rectangle(screenRect.getLeft(), screenRect.getTop(), screenRect.getWidth(), screenRect.getHeight()));
|
|
|
|
|
public BufferedImage capture(Robot robot, ViewRect viewRect) {
|
|
|
|
|
return robot.createScreenCapture(new Rectangle(viewRect.getLeft(), viewRect.getTop(), viewRect.getWidth(), viewRect.getHeight()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取屏幕范围
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect getScreenRect() {
|
|
|
|
|
public ViewRect getScreenRect() {
|
|
|
|
|
Toolkit tk = Toolkit.getDefaultToolkit();
|
|
|
|
|
return new ScreenRect(0, 0, tk.getScreenSize().width, tk.getScreenSize().height);
|
|
|
|
|
return new ViewRect(0, 0, tk.getScreenSize().width, tk.getScreenSize().height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -258,7 +262,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect findPic(String legendName, double minSimilar) {
|
|
|
|
|
public ViewRect findPic(String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
@ -272,8 +276,8 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect findPic(File pic, double minSimilar) {
|
|
|
|
|
return findPic(getScreenRect(), Imager.load(pic), minSimilar);
|
|
|
|
|
public ViewRect findPic(File pic, double minSimilar) {
|
|
|
|
|
return findPic(getScreenRect(), ImageUtil.load(pic), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -283,65 +287,65 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect findPic(BufferedImage pic, double minSimilar) {
|
|
|
|
|
public ViewRect findPic(BufferedImage pic, double minSimilar) {
|
|
|
|
|
return findPic(getScreenRect(), pic, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 应用视口查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param screenRect 应用视口
|
|
|
|
|
* @param viewRect 应用视口
|
|
|
|
|
* @param legendName 图例名称
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect findPic(ScreenRect screenRect, String legendName, double minSimilar) {
|
|
|
|
|
public ViewRect findPic(ViewRect viewRect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
|
return findPic(screenRect, new File(legend, legendName), minSimilar);
|
|
|
|
|
return findPic(viewRect, new File(legend, legendName), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 应用视口查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param screenRect 应用视口
|
|
|
|
|
* @param viewRect 应用视口
|
|
|
|
|
* @param legend 图例文件
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect findPic(ScreenRect screenRect, File legend, double minSimilar) {
|
|
|
|
|
return findPic(screenRect, Imager.load(legend), minSimilar);
|
|
|
|
|
public ViewRect findPic(ViewRect viewRect, File legend, double minSimilar) {
|
|
|
|
|
return findPic(viewRect, ImageUtil.load(legend), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取定位
|
|
|
|
|
*
|
|
|
|
|
* @param pic 参考图
|
|
|
|
|
* @param screenRect 查找范围
|
|
|
|
|
* @param viewRect 查找范围
|
|
|
|
|
* @param minSimilar 相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect findPic(ScreenRect screenRect, BufferedImage pic, double minSimilar) {
|
|
|
|
|
public ViewRect findPic(ViewRect viewRect, BufferedImage pic, double minSimilar) {
|
|
|
|
|
// 当查找区域比图片还小时,直接返回失败
|
|
|
|
|
if (screenRect.getWidth() < pic.getWidth() || screenRect.getHeight() < pic.getHeight()) {
|
|
|
|
|
if (viewRect.getWidth() < pic.getWidth() || viewRect.getHeight() < pic.getHeight()) {
|
|
|
|
|
Logger.error("视口尺寸小于图片");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取实时屏幕
|
|
|
|
|
BufferedImage screen = capture(robot, screenRect);
|
|
|
|
|
int[][] screenData = Imager.getImageRGB(screen);
|
|
|
|
|
int[][] picData = Imager.getImageRGB(pic);
|
|
|
|
|
BufferedImage screen = capture(robot, viewRect);
|
|
|
|
|
int[][] screenData = ImageUtil.getImageRGB(screen);
|
|
|
|
|
int[][] picData = ImageUtil.getImageRGB(pic);
|
|
|
|
|
|
|
|
|
|
// 得到图片左上角范围
|
|
|
|
|
int xMin = screenRect.getLeft();
|
|
|
|
|
int xMin = viewRect.getLeft();
|
|
|
|
|
// 因为坐标取像素点是从0开始,因此需要-1
|
|
|
|
|
int xMax = screenRect.getRight() - pic.getWidth();
|
|
|
|
|
int yMin = screenRect.getTop();
|
|
|
|
|
int xMax = viewRect.getRight() - pic.getWidth();
|
|
|
|
|
int yMin = viewRect.getTop();
|
|
|
|
|
// 因为坐标取像素点是从0开始,因此需要-1
|
|
|
|
|
int yMax = screenRect.getBottom() - pic.getHeight();
|
|
|
|
|
int yMax = viewRect.getBottom() - pic.getHeight();
|
|
|
|
|
|
|
|
|
|
for (int y = yMin; y <= yMax; y++) {
|
|
|
|
|
for (int x = xMin; x <= xMax; x++) {
|
|
|
|
@ -358,9 +362,9 @@ public class JMacro {
|
|
|
|
|
boolean cc = ColorUtil.isSimilar(screenData[x - xMin + pic.getWidth() / 2][y - yMin + pic.getHeight() / 2], picData[pic.getWidth() / 2][pic.getHeight() / 2]);
|
|
|
|
|
if (lt && rt && lb && rb && cc) {
|
|
|
|
|
// 进行全像素匹配
|
|
|
|
|
double similar = Imager.calcSimilar(x - xMin, y - yMin, pic.getHeight(), pic.getWidth(), screenData, picData);
|
|
|
|
|
double similar = ImageUtil.calcSimilar(x - xMin, y - yMin, pic.getHeight(), pic.getWidth(), screenData, picData);
|
|
|
|
|
if (similar >= minSimilar) {
|
|
|
|
|
return new ScreenRect(x, y, x + pic.getWidth(), y + pic.getHeight(), similar);
|
|
|
|
|
return new ViewRect(x, y, x + pic.getWidth(), y + pic.getHeight(), similar);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -377,19 +381,18 @@ public class JMacro {
|
|
|
|
|
delayNormal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void delayTap() {
|
|
|
|
|
int i = RandomUtil.randomInt(100, 500);
|
|
|
|
|
robot.delay(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void delayNormal() {
|
|
|
|
|
int i = RandomUtil.randomInt(500, 1500);
|
|
|
|
|
int i = RandomUtil.randomInt(500, 1000);
|
|
|
|
|
robot.delay(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void delayLong() {
|
|
|
|
|
int i = RandomUtil.randomInt(1500, 3000);
|
|
|
|
|
int i = RandomUtil.randomInt(1000, 2000);
|
|
|
|
|
robot.delay(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -400,7 +403,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndFindPic(File file, double minSimilar) {
|
|
|
|
|
public ViewRect waitAndFindPic(File file, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(getScreenRect(), file, minSimilar, 10, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -412,7 +415,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndFindPic(ScreenRect rect, File file, double minSimilar) {
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, File file, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(rect, file, minSimilar, 10, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -424,7 +427,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndFindPic(ScreenRect rect, String legendName, double minSimilar) {
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
@ -440,7 +443,7 @@ public class JMacro {
|
|
|
|
|
* @param unit 最长等待时间单位
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndFindPic(File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
public ViewRect waitAndFindPic(File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
return waitAndFindPic(getScreenRect(), file, minSimilar, time, unit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -454,7 +457,7 @@ public class JMacro {
|
|
|
|
|
* @param unit 最长等待时间单位
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndFindPic(ScreenRect rect, String legendName, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, String legendName, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
@ -471,9 +474,9 @@ public class JMacro {
|
|
|
|
|
* @param unit 最长等待时间单位
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndFindPic(ScreenRect rect, File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
BufferedImage image = Imager.load(file);
|
|
|
|
|
BufferedImage image = ImageUtil.load(file);
|
|
|
|
|
if (rect.getWidth() < image.getWidth()) {
|
|
|
|
|
Logger.error("查找图片区域宽度{}小于图片宽度{}", rect.getWidth(), image.getWidth());
|
|
|
|
|
return null;
|
|
|
|
@ -485,7 +488,7 @@ public class JMacro {
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
delayTap();
|
|
|
|
|
ScreenRect pic = findPic(rect, image, minSimilar);
|
|
|
|
|
ViewRect pic = findPic(rect, image, minSimilar);
|
|
|
|
|
if (pic != null) {
|
|
|
|
|
return pic;
|
|
|
|
|
}
|
|
|
|
@ -501,7 +504,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndMatchPic(ScreenRect rect, String legendName, double minSimilar) {
|
|
|
|
|
public ViewRect waitAndMatchPic(ViewRect rect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
@ -516,7 +519,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndMatchPic(ScreenRect rect, File file, double minSimilar) {
|
|
|
|
|
public ViewRect waitAndMatchPic(ViewRect rect, File file, double minSimilar) {
|
|
|
|
|
return waitAndMatchPic(rect, file, minSimilar, 10, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -530,11 +533,11 @@ public class JMacro {
|
|
|
|
|
* @param unit 最长等待时间单位
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndMatchPic(ScreenRect rect, File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
public ViewRect waitAndMatchPic(ViewRect rect, File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (true) {
|
|
|
|
|
delayTap();
|
|
|
|
|
ScreenRect matchPic = matchPic(rect, file, minSimilar);
|
|
|
|
|
ViewRect matchPic = matchPic(rect, file, minSimilar);
|
|
|
|
|
if (matchPic != null) {
|
|
|
|
|
return matchPic;
|
|
|
|
|
}
|
|
|
|
@ -550,7 +553,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect matchPic(ScreenRect rect, File file, double minSimilar) {
|
|
|
|
|
public ViewRect matchPic(ViewRect rect, File file, double minSimilar) {
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
Logger.error("file [{}] not exist", file.getAbsolutePath());
|
|
|
|
|
return null;
|
|
|
|
@ -562,13 +565,13 @@ public class JMacro {
|
|
|
|
|
offsetX = Convert.toInt(ReUtil.get("[\\S\\s]+_L([0-9]+),[0-9]+\\.png", name, 1), 0);
|
|
|
|
|
offsetY = Convert.toInt(ReUtil.get("[\\S\\s]+_L[0-9]+,([0-9]+)\\.png", name, 1), 0);
|
|
|
|
|
}
|
|
|
|
|
ScreenRect screenRect = new ScreenRect();
|
|
|
|
|
screenRect.setLeft(rect.getLeft() + offsetX);
|
|
|
|
|
screenRect.setTop(rect.getTop() + offsetY);
|
|
|
|
|
BufferedImage image = Imager.load(file);
|
|
|
|
|
screenRect.setRight(screenRect.getLeft() + image.getWidth());
|
|
|
|
|
screenRect.setBottom(screenRect.getTop() + image.getHeight());
|
|
|
|
|
return findPic(screenRect, image, minSimilar);
|
|
|
|
|
ViewRect viewRect = new ViewRect();
|
|
|
|
|
viewRect.setLeft(rect.getLeft() + offsetX);
|
|
|
|
|
viewRect.setTop(rect.getTop() + offsetY);
|
|
|
|
|
BufferedImage image = ImageUtil.load(file);
|
|
|
|
|
viewRect.setRight(viewRect.getLeft() + image.getWidth());
|
|
|
|
|
viewRect.setBottom(viewRect.getTop() + image.getHeight());
|
|
|
|
|
return findPic(viewRect, image, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -579,7 +582,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect matchPic(ScreenRect rect, String legendName, double minSimilar) {
|
|
|
|
|
public ViewRect matchPic(ViewRect rect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
@ -594,7 +597,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public boolean isMatchPic(ScreenRect rect, File file, double minSimilar) {
|
|
|
|
|
public boolean isMatchPic(ViewRect rect, File file, double minSimilar) {
|
|
|
|
|
return matchPic(rect, file, minSimilar) != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -606,7 +609,7 @@ public class JMacro {
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public boolean isMatchPic(ScreenRect rect, String legendName, double minSimilar) {
|
|
|
|
|
public boolean isMatchPic(ViewRect rect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
|