狂自私

导航

按键精灵-搜索给定区域内最后一个符合颜色值的坐标

Function get_lastPoint_coordinate_v2(left_x, left_y, right_x, right_y, color_value)
    //搜索给定区域的最后一个符合color_value颜色值的坐标,若是不存在,就返回-1,-1
    Dim result_x, result_y
    result_x = - 1 
    result_y = - 1 
    //若是给定的区域是反向区域,或者轴上存在重合,就结束函数
    If left_x >= right_x Then 
        get_lastPoint_coordinate_v2 = last_x
    End If
    If left_y >= right_y Then 
        get_lastPoint_coordinate_v2 = last_y
    End If
    
    right_down_result_x = - 1 
    right_down_result_y = - 1 
    left_down_result_x = - 1 
    left_down_result_y = - 1 
    right_up_result_x = - 1 
    right_up_result_y = - 1 
    left_up_result_x = - 1 
    left_up_result_y = - 1
    
    //分成4份,计算中点坐标
    center_x = left_x+ CInt((right_x-left_x)/2)
    center_y = left_y+CInt((right_y - left_y) / 2)
    //左上角
    FindColor left_x,left_y,center_x,center_y,color_value,intX,intY
    If intX > 0 And intY > 0 Then 
        left_up_result_x = intX
        left_up_result_y = intY
        If left_up_result_x > last_x Then 
            //更新实际需要的坐标值
            last_x = left_up_result_x
            last_y = left_up_result_y
            //避免下一次划分区域的时候又找寻到同一个坐标值
            left_up_result_x = left_up_result_x + 1
            left_up_result_y=left_up_result_y+1
        End If
    End If
    //右上角
    FindColor center_x,left_y,right_x,center_y,color_value,intX,intY
    If intX > 0 And intY > 0 Then 
        right_up_result_x = intX
        right_up_result_y = intY
        If right_up_result_y > last_y  Then 
            //更新实际需要的坐标值
            last_x = right_up_result_x
            last_y = right_up_result_y
            //避免下一次划分区域的时候又找寻到同一个坐标值
            right_up_result_x = right_up_result_x + 1
            right_up_result_y=right_up_result_y+1
        End If
    End If
    //左下角
    FindColor left_x,center_y,center_x,right_y,color_value,intX,intY
    If intX > 0 And intY > 0 Then 
        left_down_result_x = intX
        left_down_result_y = intY
        If left_down_result_x > last_x Then 
            //更新实际需要的坐标值
            last_x = left_down_result_x
            last_y = left_down_result_y
            //避免下一次划分区域的时候又找寻到同一个坐标值
            left_down_result_x = left_down_result_x + 1
            left_down_result_y=left_down_result_y+1
        End If
    End If
    //右下角
    FindColor center_x,center_y,right_x,right_y,color_value,intX,intY
    If intX > 0 And intY > 0 Then 
        right_down_result_x = intX
        right_down_result_y = intY
        If right_down_result_x > last_x Then 
            //更新实际需要的坐标值
            last_x = right_down_result_x
            last_y = right_down_result_y
            //避免下一次划分区域的时候又找寻到同一个坐标值
            right_down_result_x = right_down_result_x + 1
            right_down_result_y=right_down_result_y+1
        End If
    End If
    
    TracePrint "last_x:"&last_x & "last_y:"&last_y
    //如下排列顺序请把持不变。
    If right_down_result_x > 0 And right_down_result_y > 0 Then 
        //满足条件的坐标在右下角被找到,那么后续的函数调用也将在这个区域里面进行处理。
        get_lastPoint_coordinate_v2 right_down_result_x, right_down_result_y, right_x, right_y, color_value
    ElseIf right_up_result_x > 0 And right_up_result_y > 0 Then 
        //满足条件的坐标在右上角被找到,那么后续的函数调用也将在这个区域里面进行处理。
        get_lastPoint_coordinate_v2 right_up_result_x, right_up_result_y, right_x, center_y, color_value
    ElseIf left_down_result_x > 0 And left_down_result_y > 0 Then 
        //满足条件的坐标在左下角被找到,那么后续的函数调用也将在这个区域里面进行处理。
        get_lastPoint_coordinate_v2 left_down_result_x, left_down_result_y, center_x, right_y, color_value
    ElseIf left_up_result_x > 0 And left_up_result_y > 0 Then 
        //满足条件的坐标在左上角被找到,那么后续的函数调用也将在这个区域里面进行处理。
        get_lastPoint_coordinate_v2 left_up_result_x,left_up_result_y,center_x,center_y,color_value
    End If
End Function

如上是函数get_lastPoint_coordinate_v2的定义,调用示例:

last_x = - 1 
last_y = - 1 

get_lastPoint_coordinate_v2 1050,461,1286,658,"00FFFF"

TracePrint last_x
TracePrint last_y

如调用所示,需要定义last_x 和last_y变量,用于函数将坐标值保存下来。

posted on 2024-03-25 13:42  狂自私  阅读(9)  评论(0编辑  收藏  举报