查找指定区域内的所有颜色块 - FindColorBlockListPtr
函数简介
查找指定图像内符合指定颜色范围的所有颜色块坐标点。
接口名称
FindColorBlockListPtr
DLL调用
long FindColorBlockListPtr(long ola, long image_ptr, string colors, int min_count, int block_width, int block_height, int dedup);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| image_ptr | 长整数型 | 要搜索的图片句柄 |
| colors | 字符串 | 颜色模型配置字符串,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:3278FA~6496FF |
| min_count | 整数型 | 在指定宽高的颜色块中,符合颜色条件的最小像素数量 |
| block_width | 整数型 | 颜色块的宽度(像素) |
| block_height | 整数型 | 颜色块的高度(像素) |
| dedup | 整数型 | 是否去重:0 不去重、1 去重 |
示例
C++
long instance = CreateCOLAPlugInterFace();
// hwnd 为绑定的窗口句柄
long img = GetScreenDataPtr(instance, 0, 0, 0, 0);
// 查找所有符合条件的颜色块,去重
long resultPtr = FindColorBlockListPtr(instance, img, "3278FA~6496FF", 100, 20, 20, 1);
if (resultPtr != 0) {
// resultPtr 指向JSON字符串 [{"x":1,"y":2},...]
char* json = GetStringFromPtr(instance, resultPtr);
printf("结果: %s\n", json);
FreeStringPtr(instance, resultPtr);
}
FreeImagePtr(instance, img);
Python
# 待补充
返回值
长整数型:返回JSON字符串指针,格式为 [{"x":1,"y":2},{"x":2,"y":1}]。失败返回0。
注意事项
- 返回的字符串指针需调用 FreeStringPtr 释放内存。
