函数简介:

查找指定区域内的图片,位图必须是24位色格式,支持透明色,当图像上下左右4个顶点的颜色一样时,则这个颜色将作为透明色处理.

这个函数可以查找多个图片,只返回第一个找到的X Y坐标.

函数原型:

long FindPic(x1, y1, x2, y2, pic_name, delta_color, sim, dir, intX, intY)

参数定义:

x  整形数 : 区域的左上X坐标
y  整形数 : 区域的左上Y坐标
x2  整形数 :
区域的右下x 坐标
y2  整形数 : 区域的右下Y 坐标

pic_name 字符串 :  文件 格式为"D:\\123.BMP|D:\\1234.BMP|345.bmp"..   MFC  其他的“d:\123.bmp”
color 字符串 : 颜色 格式为"RRGGBB-DRDGDB", 比如"123456-000000|aabbcc-202020".注意,这里只支持RGB颜色.
sim 双精度浮点数 : 相似度, 取值范围0.1 - 1.0

dir 整形数:查找方向 0: 从左到右,从上到下 1: 从左到右,从下到上 2: 从右到左,从上到下 3: 从右到左, 从下到上
intX 变参指针 :返回 X坐标
intY
变参指针:返回Y坐标

返回值:

整形数:
找到返回1,如果没找到返回-1

 

示例:

 

 CString str,str1,str2,str3;
 GetDlgItemText(EDIT2, str);
 GetDlgItemText(EDIT3, str1);
 GetDlgItemText(EDIT4, str2);
 GetDlgItemText(EDIT5, str3);
 int x = 0, y = 0;
 if (g_lw)
 {
  g_lw->FindPic( 0, 0, 2000, 2000, str1, str2, atof(str3), &x, &y);
  //g_lw->Add(5, 6,(long*)&x);
  //str.Format("5+6=%d", x);

  str.Format("坐标x=%d 坐标y=%d", x, y);
  SetDlgItemText(EDIT1, str);
  return;
 }