上传备份

wjdr
王兵 1 year ago
parent cf2bad116d
commit 363ab9464e

@ -2,6 +2,7 @@ package com.example.jmacro.wjdr;
import cn.hutool.core.util.RandomUtil;
import com.example.jmacro.wjdr.base.Legend;
import com.example.jmacro.wjdr.base.ViewColor;
import com.example.jmacro.wjdr.base.ViewPoint;
import com.example.jmacro.wjdr.base.ViewRect;
import com.example.jmacro.wjdr.util.ColorUtil;
@ -38,7 +39,7 @@ public abstract class JMacro {
try {
// 机器人初始化
this.robot = new JRoot();
this.robot.setAutoDelay(100);
this.robot.setAutoDelay(30);
this.startFocus();
} catch (AWTException e) {
throw new RuntimeException(e);
@ -120,7 +121,7 @@ public abstract class JMacro {
double absX = Math.abs(startX - endX);
double absY = Math.abs(startY - endY);
double absZ = Math.sqrt(Math.pow(absX, 2) + Math.pow(absY, 2));
int times = (int) (absZ / 30 + (absZ % 30 > 0 ? 1 : 0));
int times = (int) (absZ / 10 + (absZ % 10 > 0 ? 1 : 0));
int interval = Math.min(500 / times, 10);
times = Math.min(times, 10);
@ -130,7 +131,7 @@ public abstract class JMacro {
int dx = (int) (startX + (endX - startX) * d);
int dy = (int) (startY + (endY - startY) * d);
robot.mouseMove(dx, dy);
delay(RandomUtil.randomInt(interval - 10, interval + 10));
delay(RandomUtil.randomInt(interval - 5, interval + 5));
}
} else {
robot.mouseMove(endX, endY);
@ -822,6 +823,21 @@ public abstract class JMacro {
return waitAndMatchPic(legend.getFile(), legend.getLocation(), minSimilar, seconds);
}
/**
*
*
* @param color
* @return
*/
public boolean matchColor(ViewColor color) {
ViewRect of = of(color.getX(), color.getY(), color.getX(), color.getY());
// 获取实时屏幕
BufferedImage pointImage = capture(robot, of);
ImageUtil.show(pointImage);
int[][] pointData = ImageUtil.getImageRGB(pointImage);
return ColorUtil.isSimilar(pointData[0][0], color.getColor());
}
/**
*
*
@ -863,4 +879,25 @@ public abstract class JMacro {
public ViewPoint of(ViewPoint relativePoint) {
return of(relativePoint.getX(), relativePoint.getY());
}
/**
*
*
* @return
*/
public ViewColor of(int x, int y, String hexColor) {
int ox = getFocusRect().getLeft();
int oy = getFocusRect().getTop();
return new ViewColor(x + ox, y + oy, hexColor);
}
/**
*
*
* @param relativePoint
* @return
*/
public ViewColor of(ViewPoint relativePoint, String hexColor) {
return of(relativePoint.getX(), relativePoint.getY(), hexColor);
}
}

@ -0,0 +1,45 @@
package com.example.jmacro.wjdr.base;
import cn.hutool.core.util.StrUtil;
/**
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class ViewColor extends ViewPoint {
/**
*
*/
private int color;
/**
* @param x
* @param y
* @param hexColor argb #FFFFFF
*/
public ViewColor(int x, int y, String hexColor) {
super(x, y);
this.color = Integer.parseInt(StrUtil.removePrefix(hexColor, "#"), 16);
}
public ViewColor(int x, int y, int color) {
super(x, y);
this.color = color;
}
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public String getHexColor() {
return "#" + Integer.toHexString(color);
}
}

@ -99,13 +99,19 @@ public class Location extends JFrame {
super.mouseReleased(e);
x = e.getX();
y = e.getY();
Logger.info("坐标采集:");
Logger.info("=========================坐标采集=========================");
Logger.info("屏幕坐标:[{},{}]", x, y);
Logger.info("相对坐标:[{},{}]用法macro.of({},{})", x - originX, y - originY, x - originX, y - originY);
Logger.info("相对坐标:[{},{}]", x - originX, y - originY);
String hexColor = Integer.toHexString(capture.getRGB(x, y) & 0xFFFFFF);
Logger.info("坐标色值:[#{}]", hexColor);
Logger.info("用法示例:");
Logger.info("1、坐标点击mouseLeftClick(of({},{}));", x - originX, y - originY);
Logger.info("2、色值比对matchColor(of({},{},{}));", x - originX, y - originY, hexColor);
Logger.info("=========================坐标采集=========================");
close();
JOptionPane.showConfirmDialog(null, StrUtil.format("屏幕坐标:[{},{}]\n相对坐标[{},{}]\n坐标色值[#{}]", x, y, x - originX, y - originY, hexColor), "坐标信息", 1);
JOptionPane.showMessageDialog(null, StrUtil.format("屏幕坐标:[{},{}]\n相对坐标[{},{}]\n坐标色值[#{}]", x, y, x - originX, y - originY, hexColor), "坐标信息", 1);
}
});

@ -10,11 +10,17 @@ package com.example.jmacro.wjdr.util;
public class ColorUtil {
/**
*
*
*
*/
private static final double THRESHOLD_OF_SIMILARITY = 0.95D;
/**
* argb
*
* @param colorInt1 1
* @param colorInt2 2
* @return
* @param colorInt1 1
* @param colorInt2 2
* @return
*/
public static double calculateSimilarity(int colorInt1, int colorInt2) {
// 计算RGB各分量的平方差
@ -31,6 +37,13 @@ public class ColorUtil {
return 1 - distance / Math.sqrt(3 * 255 * 255);
}
/**
* argb
*
* @param colorInt1 1
* @param colorInt2 2
* @return
*/
public static boolean isSimilar(int colorInt1, int colorInt2) {
// 透明色认为相似
if ((colorInt1 >> 24 & 0xff) == 0) {
@ -40,6 +53,6 @@ public class ColorUtil {
if ((colorInt2 >> 24 & 0xff) == 0) {
return true;
}
return calculateSimilarity(colorInt1, colorInt2) > 0.95d;
return calculateSimilarity(colorInt1, colorInt2) > THRESHOLD_OF_SIMILARITY;
}
}

@ -45,10 +45,15 @@
<Insets left="6.0" />
</padding>
</HBox>
<ImageView fx:id="preview" layoutX="5.0" layoutY="195.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="6.0" AnchorPane.leftAnchor="6.0" AnchorPane.rightAnchor="6.0" AnchorPane.topAnchor="200.0">
<viewport>
<Rectangle2D height="100.0" width="188.0" />
</viewport></ImageView>
<Pane layoutX="6.0" layoutY="200.0" style="-fx-border-color: #ddd;" AnchorPane.bottomAnchor="6.0" AnchorPane.leftAnchor="6.0" AnchorPane.rightAnchor="6.0" AnchorPane.topAnchor="200.0">
<children>
<ImageView fx:id="preview" pickOnBounds="true" preserveRatio="true">
<viewport>
<Rectangle2D height="100.0" width="188.0" />
</viewport>
</ImageView>
</children>
</Pane>
<Label layoutX="40.0" layoutY="165.0" prefHeight="35.0" prefWidth="200.0" text="区域预览" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="160.0">
<padding>
<Insets left="6.0" />

Loading…
Cancel
Save

Powered by TurnKey Linux.