查找绑定窗口图片2 - FindWindowsFromPtr
函数简介
在绑定窗口的指定区域内查找指定图像,模板通过内存指针传入,返回第一个匹配结果。
接口名称
FindWindowsFromPtr
DLL调用
long FindWindowsFromPtr(long instance, int x1, int y1, int x2, int y2, long templ, string deltaColor, double matchVal, int dir);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| x1 | 整数型 | 搜索区域左上角X坐标 |
| y1 | 整数型 | 搜索区域左上角Y坐标 |
| x2 | 整数型 | 搜索区域右下角X坐标 |
| y2 | 整数型 | 搜索区域右下角Y坐标 |
| templ | 长整数型 | OLAImage对象的地址,由LoadImage等接口生成 |
| deltaColor | 字符串 | 颜色差值,格式为"RRGGBB",如"101010" |
| matchVal | 双精度浮点数 | 相似度,如0.85,最大为1 |
| dir | 整数型 | 查找方向:0-从左到右从上到下;1-从左到右从下到上;2-从右到左从上到下;3-从右到左从下到上;4-从中心往外查找;5-从上到下从左到右;6-从上到下从右到左;7-从下到上从左到右;8-从下到上从右到左 |
示例
C++
long instance = CreateCOLAPlugInterFace();
BindWindow(instance, hwnd, 0, 0, 0);
long templ = LoadImage(instance, "templ.bmp");
// 通过内存指针在窗口中查找第一个匹配结果
long resultPtr = FindWindowsFromPtr(instance, 0, 0, 0, 0, templ, "101010", 0.85, 0);
char* result = GetStringFromPtr(instance, resultPtr);
FreeStringPtr(instance, resultPtr);
Python
# 待补充
返回值
字符串指针,返回JSON格式的匹配结果。DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。
返回数据格式:
{
"MatchVal": 0.85,
"MatchState": true,
"Index": 0,
"X": 100,
"Y": 200,
"Width": 100,
"Height": 100
}
| 字段名 | 类型 | 说明 |
|---|---|---|
| MatchVal | 浮点数 | 匹配相似度。 |
| MatchState | 布尔 | 是否匹配成功。 |
| Index | 整数 | 结果索引(从 0 开始)。 |
| X | 整数 | X 坐标。 |
| Y | 整数 | Y 坐标。 |
| Width | 整数 | 宽度。 |
| Height | 整数 | 高度。 |
注意事项
- x1、y1、x2、y2都传0时,将搜索整个窗口客户区
