实现原理
- 截取当前屏幕
- 读取需要查找的图片
- 抽取特征
- 根据特征遍历屏幕找到符合特征的块
- 把找到的特征块和图片进行精确对比
代码如下
- 首先定义图片查找接口
public interface ImageFinder {
/**
* 查询到匹配的图片
* @param image 需要查找的图片
* @return
*/
List<Coordinate> match(BufferedImage image,double percent);
}
- 定义查找到的返回坐标
public class Coordinate {
private int x;
private int y;
public Coordinate(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
- 特征类
public class ColorBlock {
int[][] rgbs;
private int width;
private int height;
private Point leftTop;
private Point rightTop;
private Point leftBottom;
private Point rightBottom;
private Point center;
private int count = 0;
public ColorBlock(BufferedImage image){
this.width = image.getWidth();
this.height = image.getHeight();
this.rgbs = new int[this.width][this.height];
for(int x=0;x<this.width;x++){
for(int y=0; y<this.height;y++){
this.rgbs[x][y] = image.getRGB(x,y);
count =