|
|
|
@ -287,6 +287,9 @@ public class JMacro {
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect findPic(ScreenRect screenRect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
|
return findPic(screenRect, new File(legend, legendName), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -314,6 +317,7 @@ public class JMacro {
|
|
|
|
|
public ScreenRect findPic(ScreenRect screenRect, BufferedImage pic, double minSimilar) {
|
|
|
|
|
// 当查找区域比图片还小时,直接返回失败
|
|
|
|
|
if (screenRect.getWidth() < pic.getWidth() || screenRect.getHeight() < pic.getHeight()) {
|
|
|
|
|
Logger.error("视口尺寸小于图片");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -352,6 +356,11 @@ public class JMacro {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// try {
|
|
|
|
|
// ImgUtil.write(screen,"png", new FileOutputStream("D://1.png"));
|
|
|
|
|
// } catch (FileNotFoundException e) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -458,6 +467,55 @@ public class JMacro {
|
|
|
|
|
}, time, unit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param rect 参照区域
|
|
|
|
|
* @param legendName 图例名称
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndMatchPic(ScreenRect rect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
|
return waitAndMatchPic(rect, new File(legend, legendName), minSimilar, 10, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param rect 参照区域
|
|
|
|
|
* @param file 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndMatchPic(ScreenRect rect, File file, double minSimilar) {
|
|
|
|
|
return waitAndMatchPic(rect, file, minSimilar, 10, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param rect 参照区域
|
|
|
|
|
* @param file 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param time 最长等待时间
|
|
|
|
|
* @param unit 最长等待时间单位
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect waitAndMatchPic(ScreenRect rect, File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (true) {
|
|
|
|
|
delayTap();
|
|
|
|
|
ScreenRect matchPic = matchPic(rect, file, minSimilar);
|
|
|
|
|
if (matchPic != null) {
|
|
|
|
|
return matchPic;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, time, unit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配图片
|
|
|
|
|
*
|
|
|
|
@ -467,6 +525,10 @@ public class JMacro {
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect matchPic(ScreenRect rect, File file, double minSimilar) {
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
Logger.error("file [{}] not exist", file.getAbsolutePath());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String name = file.getName();
|
|
|
|
|
int offsetX = 0;
|
|
|
|
|
int offsetY = 0;
|
|
|
|
@ -480,7 +542,6 @@ public class JMacro {
|
|
|
|
|
BufferedImage image = Imager.load(file);
|
|
|
|
|
screenRect.setRight(screenRect.getLeft() + image.getWidth());
|
|
|
|
|
screenRect.setBottom(screenRect.getTop() + image.getHeight());
|
|
|
|
|
System.out.println(screenRect.toString());
|
|
|
|
|
return findPic(screenRect, image, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -493,6 +554,9 @@ public class JMacro {
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ScreenRect matchPic(ScreenRect rect, String legendName, double minSimilar) {
|
|
|
|
|
if (!legendName.endsWith(".png")) {
|
|
|
|
|
legendName = legendName + ".png";
|
|
|
|
|
}
|
|
|
|
|
return matchPic(rect, new File(legend, legendName), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|