我有两个Bitmap对象,A和B,其中B是A的一部分(在图上).
怎么找出B在A的坐标(Point)
我的思路是用Bitmap.GetPixel方法逐点比对,但不知道怎么循环,请大家指教一下!
循环法代码:
Function FindMap(ByVal Y As Image, ByVal Z As Image) As Point
Dim 原图 As Bitmap = CType(Y, Bitmap)
Dim 找图 As Bitmap = CType(Z, Bitmap)
Dim 相同次数 As Integer
Dim 剩余区域 As Integer = 原图.Width * 原图.Height - 找图.Width * 找图.Height
If 剩余区域 < 0 Then
Return Nothing
End If
For 原图X坐标 = 0 To 原图.Width - 1
For 原图Y坐标 = 0 To 原图.Height - 1
For 找图X坐标 = 0 To 找图.Width - 1
If 原图X坐标 + 找图.Width > 原图.Width Then
Exit For
End If
For 找图Y坐标 = 0 To 找图.Height - 1
If 找图Y坐标 + 找图.Height > 原图.Height Then
Exit For
End If
If 原图.GetPixel(原图X坐标 + 找图X坐标, 原图Y坐标 + 找图Y坐标) <> 找图.GetPixel(找图X坐标, 找图Y坐标) Then
相同次数 = 0
Exit For
Else
相同次数 += 1
End If
If 相同次数 = 找图.Width * 找图.Height Then
Return New Point(原图X坐标, 原图Y坐标)
End If
Next
Next
Next
Next
Return Nothing
End Function
问题:图片大了就一直循环出不来.
我是包子!