王兵 1 year ago
parent a8c6d1da89
commit 15bb5d817e

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="starter-jmacro" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="starter-jpg2mp4" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources/lib" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="http://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="aliyun" />
<option name="name" value="Aliyun Repository" />
<option name="url" value="https://maven.aliyun.com/repository/public" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>starter-jmacro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<!--<packaging>war</packaging>--><!--需要打包成war时放开-->
<name>starter-jmacro</name>
<description>project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>8</java.version>
<maven.test.skip>true</maven.test.skip>
</properties>
<repositories>
<!-- 将中央仓库地址指向阿里云聚合仓库,提高下载速度 -->
<repository>
<id>aliyun</id>
<name>Aliyun Repository</name>
<layout>default</layout>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
<pluginRepositories>
<!-- 将插件的仓库指向阿里云聚合仓库解决低版本maven下载插件异常或提高下载速度 -->
<pluginRepository>
<id>aliyun</id>
<name>Aliyun Repository</name>
<url>https://maven.aliyun.com/repository/public</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.26</version>
</dependency>
</dependencies>
<build>
<!-- 项目名称 -->
<finalName>${artifactId}-${version}</finalName>
<!-- 默认的主代码目录 -->
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<!-- 包含lib中所有jar包 -->
<resource>
<directory>${basedir}/src/main/resources/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,40 @@
package com.example.jmacro;
public class ColorUtil {
/**
*
*
* @param colorInt1 1
* @param colorInt2 2
* @return
*/
public static double calculateSimilarity(int colorInt1, int colorInt2) {
// 计算RGB各分量的平方差
int[] color1 = {(colorInt1 >> 16) & 0xFF, (colorInt1 >> 8) & 0xFF, colorInt1 & 0xFF};
int[] color2 = {(colorInt2 >> 16) & 0xFF, (colorInt2 >> 8) & 0xFF, colorInt2 & 0xFF};
int diffR = (color1[0] - color2[0]) * (color1[0] - color2[0]);
int diffG = (color1[1] - color2[1]) * (color1[1] - color2[1]);
int diffB = (color1[2] - color2[2]) * (color1[2] - color2[2]);
// 计算欧氏距离
double distance = Math.sqrt(diffR + diffG + diffB);
// 计算两个颜色之间的相似度(距离越小,相似度越高)
double similarity = 1 - distance / Math.sqrt(3 * 255 * 255);
return similarity;
}
public static boolean isSimilar(int colorInt1, int colorInt2) {
return calculateSimilarity(colorInt1, colorInt2) > 0.99d;
}
public static void main(String[] args) {
int color1 = 0xffffff; // 白色
int color2 = 0xfefefe; // 非常接近白色的颜色
double similarity = calculateSimilarity(color1, color2);
System.out.println("Similarity: " + similarity); // 输出相似度
}
}

@ -0,0 +1,58 @@
//package com.example.jmacro;
//
//import java.awt.AWTException;
//import java.awt.Point;
//import java.awt.Rectangle;
//import java.awt.Toolkit;
//import java.awt.image.BufferedImage;
//
//public class CutImageTool {
//
// /**
// * 截取指定左上角坐标,右下角坐标的屏幕区域图像
// */
// public static BufferedImage getScreeImage(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) throws AWTException {
// int width = bottomRightX - topLeftX;
// int height = bottomRightY - topLeftY;
// Rectangle rectangle = new Rectangle(topLeftX, topLeftY, width, height);
// return CommonUtil.getRobot().createScreenCapture(rectangle);
// }
//
// /**
// * 截取指定左上角坐标,右下角坐标的屏幕区域图像
// * @param topLeft
// * @param bottomRight
// * @return
// * @throws AWTException
// */
// public static BufferedImage getScreeImage(Point topLeft, Point bottomRight) throws AWTException {
// int X = topLeft.x;
// int Y = topLeft.y;
// int width = bottomRight.x - topLeft.x;
// int height = bottomRight.y - topLeft.y;
// Rectangle rectangle = new Rectangle(X, Y, width, height);
// return CommonUtil.getRobot().createScreenCapture(rectangle);
// }
//
// /**
// * 截取指定屏幕区域图像
// * @param topLeft
// * @param bottomRight
// * @return
// * @throws AWTException
// */
// public static BufferedImage getScreeImage(Rectangle rectangle) throws AWTException {
// return CommonUtil.getRobot().createScreenCapture(rectangle);
// }
//
// /**
// * 截取全屏幕图像
// * @return
// * @throws AWTException
// */
// public static BufferedImage getFullScreeImage() throws AWTException {
// Rectangle rectangle = new Rectangle(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
// return CommonUtil.getRobot().createScreenCapture(rectangle);
// }
//}
//

@ -0,0 +1,297 @@
//package com.example.jmacro;
//
//import java.awt.AWTException;
//import java.awt.Point;
//import java.awt.image.BufferedImage;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.io.ObjectInputStream;
//import java.util.ArrayList;
//import java.util.List;
//
//
///**
// * 图像匹配
// * @author Jiyh
// *
// */
//public class ImageMatchTools {
//
// /**
// * 全屏幕查找指定区域的图像
// * @param topLeft
// * @param bottomRight
// * @return
// * @throws AWTException
// */
// public static int[] findImageInFullScreen(Point topLeft, Point bottomRight) throws AWTException {
// BufferedImage smallImage = CutImageTool.getScreeImage(topLeft, bottomRight);
// BufferedImage screencapture = CutImageTool.getFullScreeImage();
//
// return findImage(screencapture, smallImage);
// }
//
// /**
// * 全屏幕区域查找指定文件代表的图像
// * @param bigImage
// * @param smallImageFileName
// * @return
// * @throws AWTException
// */
// public static int[] findImage( String smallImageFileName) throws AWTException {
// BufferedImage screenImage = CutImageTool.getFullScreeImage();
// return findImage(screenImage, ImageMatchTools.readImageRGB2Object(smallImageFileName));
// }
//
// /**
// * 在指定屏幕区域查找指定文件代表的图像
// * @param bigImage
// * @param smallImageFileName
// * @return
// */
// public static int[] findImage(BufferedImage creenImage, String smallImageFileName) {
// return findImage(creenImage, ImageMatchTools.readImageRGB2Object(smallImageFileName));
// }
//
// /**
// * 在游戏屏幕区域查找指定文件代表的图像
// * @param gameScreenTopLeft
// * @param gameScreenBottomRight
// * @param smallImageFileName
// * @return
// * @throws AWTException
// */
// public static int[] findImageInGameScreen( String smallImageFileName) throws AWTException {
// BufferedImage gameScreenImage = CutImageTool.getScreeImage(GameScreen.topLeft, GameScreen.bottomRight);
// return findImage(gameScreenImage, ImageMatchTools.readImageRGB2Object(smallImageFileName));
// }
//
// /**
// * 在指定屏幕区域查找指定二位数组代表的图像
// * @param bigImage
// * @param smallRgbArray
// * @return
// */
// public static int[] findImage(BufferedImage bigImage, int[][] smallRgbArray) {
// int bigWidth = bigImage.getWidth();
//
// int bigHeight = bigImage.getHeight();
//
// int smallWidth = smallRgbArray.length;
//
// int smallHeight = smallRgbArray[0].length;
//
// int[][] bigData = getImageRGB(bigImage);
//
// int[][] smallData = smallRgbArray;
//
// int[] target = { -1, -1 };
//
// int yEnd = bigHeight - smallHeight;
// int xEnd = bigWidth - smallWidth;
//
// for (int y = 0; y < yEnd; y++) {
// for (int x = 0; x < xEnd; x++) {
// // 对关键点进行先期匹配,降低运算复杂度。如果关键点本身就不匹配,就没必要再去匹配小图的每一个像素点
// if (bigData[x][y] == smallData[0][0] // 左上角
// && bigData[x + smallWidth - 1][y]
// == smallData[smallWidth - 1][0] // 右上角
// && bigData[x][y + smallHeight - 1] == smallData[0][smallHeight - 1] // 左下角
// && bigData[x + smallWidth - 1][y + smallHeight - 1] == smallData[smallWidth - 1][smallHeight
// - 1] // 右下角
// && bigData[x + smallWidth / 2][y + smallHeight / 2] == smallData[smallWidth / 2][smallHeight
// / 2]) {
//
// // 进行全像素匹配
// boolean isMatched = checkAllMatch(x, y, smallHeight, smallWidth, bigData, smallData);
// if (isMatched) {
// System.out.println("像素点X" + x + " : Y" + y + ",对应的值为:" + bigData[x][y]);
//
// // 获取小图的中心位置的点
// int centerX = x + smallWidth/2;
// int centerY = y + smallHeight/2;
// target[0] = centerX;
// target[1] = centerY;
// return target;
// }
// }
//
// }
// }
//
// return target;
// }
//
// /**
// * 在指定屏幕区域查找指定图像
// * @param bigImage
// * @param smallImage
// * @return
// */
// public static int[] findImage(BufferedImage bigImage, BufferedImage smallImage) {
//
// int bigWidth = bigImage.getWidth();
//
// int bigHeight = bigImage.getHeight();
//
// int smallWidth = smallImage.getWidth();
//
// int smallHeight = smallImage.getHeight();
//
// int[][] bigData = getImageRGB(bigImage);
//
// int[][] smallData = getImageRGB(smallImage);
//
// int[] target = { -1, -1 };
//
// int yEnd = bigHeight - smallHeight;
// int xEnd = bigWidth - smallWidth;
//
// for (int y = 0; y < yEnd; y++) {
// for (int x = 0; x < xEnd; x++) {
// // 对关键点进行先期匹配,降低运算复杂度。如果关键点本身就不匹配,就没必要再去匹配小图的每一个像素点
// if (bigData[x][y] == smallData[0][0] // 左上角
// && bigData[x + smallWidth - 1][y] == smallData[smallWidth - 1][0] // 右上角
// && bigData[x][y + smallHeight - 1] == smallData[0][smallHeight - 1] // 左下角
// && bigData[x + smallWidth - 1][y + smallHeight - 1] == smallData[smallWidth - 1][smallHeight
// - 1] // 右下角
// && bigData[x + smallWidth / 2][y + smallHeight / 2] == smallData[smallWidth / 2][smallHeight
// / 2]) {
//
// // 进行全像素匹配
// boolean isMatched = checkAllMatch(x, y, smallHeight, smallWidth, bigData, smallData);
// if (isMatched) {
// System.out.println("像素点X" + x + " : Y" + y + ",对应的值为:" + bigData[x][y]);
//
// // 获取小图的中心位置的点
// int centerX = x + smallWidth/2;
// int centerY = y + smallHeight/2;
// target[0] = centerX;
// target[1] = centerY;
// return target;
// }
// }
//
// }
// }
//
// return target;
// }
//
// private static boolean checkAllMatch(int x, int y, int smallHeight, int smallWidth, int[][] bigData,
// int[][] smallData) {
// boolean isMatched = true;
// for (int smallY = 0; smallY < smallHeight; smallY++) {
// for (int smallX = 0; smallX < smallWidth; smallX++) {
// // 如果发现有一个像素点,两者的值不一样,则认为不相等,如果不相等,则没必要继续比较其它点.
// if (bigData[x + smallX][y + smallY] != smallData[smallX][smallY]) {
// isMatched = false;
// return isMatched;
// }
// }
// }
// return isMatched;
// }
//
// public static int[][] getImageRGB(BufferedImage bfImage) {
// int width = bfImage.getWidth();
//
// int height = bfImage.getHeight();
//
// int[][] result = new int[width][height];
//
// for (int y = 0; y < height; y++) {
// for (int x = 0; x < width; x++) {
// // 对某个像素点的RGB编码并存入数据库
// result[x][y] = bfImage.getRGB(x, y) & 0xFFFFFF;
//
// // 单独获取每一个像素点的RedGreen和Blue的值。
//
// // int r = (bfImage.getRGB(x, y) & 0xFF0000) >> 16;
//
// // int g = (bfImage.getRGB(x, y) & 0xFF00) >> 8;
//
// // int b = bfImage.getRGB(x, y) & 0xFF;
//
// }
//
// }
//
// return result;
//
// }
//
// public static int[][] readImageRGB(String fileName) {
// List<int[]> rgbList = new ArrayList<int[]>();
// TxtFileReader tfr = null;
// try {
// tfr = new TxtFileReader(fileName);
// String line = null;
// while ((line = tfr.readLine()) != null){
// String[] rgbStringArray = line.split(",");
// int[] rfgArray = new int[rgbStringArray.length];
// for (int i = 0; i < rgbStringArray.length; i++) {
// rfgArray[i] = Integer.parseInt(rgbStringArray[i]);
// }
// rgbList.add(rfgArray);
// }
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }finally {
// if(tfr != null){
// tfr.close();
// }
// }
//
// int[][] rgbArray = new int[rgbList.size()][];
// for (int i = 0; i < rgbArray.length; i++) {
// rgbArray[i] = rgbList.get(i);
// }
//
// return rgbArray;
// }
// public static int[][] readImageRGB2Object(String filePath) {
// File file = new File(filePath);
// FileInputStream fis = null;
// ObjectInputStream ois = null;
// try {
// fis = new FileInputStream(file);
// ois = new ObjectInputStream(fis);
// Object data = ois.readObject();
// return (int[][])data;
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }finally {
// if(ois != null){
// try {
// ois.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// if(fis != null){
// try {
// fis.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
//
// return null;
// }
//
//}
//

@ -0,0 +1,24 @@
package com.example.jmacro;
import java.io.File;
/**
*
*/
public class JMacro {
/**
*
*/
private File legend;
public JMacro() {
}
/**
*
*/
private boolean location(){
}
}

@ -0,0 +1,15 @@
package com.example.jmacro;
import cn.hutool.core.util.StrUtil;
public class LogUtil {
public static void info(String log, Object... arg) {
System.out.println(StrUtil.format(log, arg));
}
public static void error(String log, Object... arg) {
System.err.println(StrUtil.format(log, arg));
}
}

@ -0,0 +1,118 @@
package com.example.jmacro;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.json.JSONUtil;
import org.w3c.dom.css.Rect;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class Main {
static Robot robot;
static {
try {
robot = new Robot();
} catch (AWTException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws AWTException {
int[] aa = findImage(loadScreen(), loadAnchor("野外"));
System.out.println(JSONUtil.toJsonStr(aa));
}
public static Rect findImage(BufferedImage bigImage, BufferedImage smallImage) {
int bigWidth = bigImage.getWidth();
int bigHeight = bigImage.getHeight();
int smallWidth = smallImage.getWidth();
int smallHeight = smallImage.getHeight();
int[][] bigData = getImageRGB(bigImage);
int[][] smallData = getImageRGB(smallImage);
int[] target = {-1, -1};
int yEnd = bigHeight - smallHeight;
int xEnd = bigWidth - smallWidth;
for (int y = 0; y < yEnd; y++) {
for (int x = 0; x < xEnd; x++) {
// 对关键点进行先期匹配,降低运算复杂度。如果关键点本身就不匹配,就没必要再去匹配小图的每一个像素点
if (ColorUtil.isSimilar(bigData[x][y], smallData[0][0]) && // 左上角
ColorUtil.isSimilar(bigData[x + smallWidth - 1][y], smallData[smallWidth - 1][0]) &&// 右上角
ColorUtil.isSimilar(bigData[x][y + smallHeight - 1], smallData[0][smallHeight - 1]) &&// 左下角
ColorUtil.isSimilar(bigData[x + smallWidth - 1][y + smallHeight - 1], smallData[smallWidth - 1][smallHeight - 1]) && // 右下角
ColorUtil.isSimilar(bigData[x + smallWidth / 2][y + smallHeight / 2], smallData[smallWidth / 2][smallHeight / 2]) //中心点
) {
// 进行全像素匹配
boolean isMatched = checkAllMatch(x, y, smallHeight, smallWidth, bigData, smallData);
if (isMatched) {
System.out.println("像素点X" + x + " : Y" + y + ",对应的值为:" + bigData[x][y]);
// 获取小图的中心位置的点
int centerX = x + smallWidth / 2;
int centerY = y + smallHeight / 2;
target[0] = centerX;
target[1] = centerY;
return new int[][]{{x,y},};
return new Rect
}
}
}
}
return target;
}
public static int[][] getImageRGB(BufferedImage bfImage) {
int width = bfImage.getWidth();
int height = bfImage.getHeight();
int[][] result = new int[width][height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// 对某个像素点的RGB编码并存入数据库
result[x][y] = bfImage.getRGB(x, y) & 0xFFFFFF;
// 单独获取每一个像素点的RedGreen和Blue的值。
// int r = (bfImage.getRGB(x, y) & 0xFF0000) >> 16;
// int g = (bfImage.getRGB(x, y) & 0xFF00) >> 8;
// int b = bfImage.getRGB(x, y) & 0xFF;
}
}
return result;
}
private static boolean checkAllMatch(int x, int y, int smallHeight, int smallWidth, int[][] bigData, int[][] smallData) {
boolean isMatched = true;
for (int smallY = 0; smallY < smallHeight; smallY++) {
for (int smallX = 0; smallX < smallWidth; smallX++) {
// 如果发现有一个像素点,两者的值不一样,则认为不相等,如果不相等,则没必要继续比较其它点.
if (!ColorUtil.isSimilar(bigData[x + smallX][y + smallY], smallData[smallX][smallY])) {
isMatched = false;
return isMatched;
}
}
}
return isMatched;
}
// 获取屏幕截图
static BufferedImage loadScreen() {
// 获取缺省工具包
Toolkit tk = Toolkit.getDefaultToolkit();
// 屏幕尺寸规格
Dimension di = tk.getScreenSize();
LogUtil.info("获取屏幕尺寸({},{}", di.width, di.height);
Rectangle rec = new Rectangle(0, 0, di.width, di.height);
return robot.createScreenCapture(rec);
}
static BufferedImage loadAnchor(String anchor) {
return ImgUtil.read(new File("anchor", anchor + ".png"));
}
}
Loading…
Cancel
Save

Powered by TurnKey Linux.