我正在尝试在屏幕的 382x336 px 区域中获取所有像素,检测某些颜色并单击最后检测到的其中一个(对于游戏)。
我的问题是我的扫描需要花费大量时间来覆盖该区域,因此我的AI无法跟上游戏。
有没有更好的方法来实现我的目标?或者有没有办法优化我的代码以更快地运行?
主要代码:
Dim LFE, LNE As Point
For YI As Integer = 264 To 600 Step 1
P.Y = YI
LFE = New Point(0, 0)
LNE = New Point(0, 0)
For XI As Integer = 493 To 875 Step 1
P.X = XI
If GetPoint(P) = "ffef3031" OrElse GetPoint(P) = "fff0d381" OrElse GetPoint(P) = "ff19a3ff" OrElse GetPoint(P) = "ff795f14" Then
LNE = P
ElseIf GetPoint(P) = "ffee1600" Then
LFE = P
End If
Next
Next
If LFE = New Point(0, 0) Then
If Not LNE = New Point(0, 0) Then
Cursor.Position = LNE
End If
Else
Cursor.Position = LFE
End If
GetPoint
功能:
Function GetPoint(ByVal Pnt As Point) As String
Dim a As New Drawing.Bitmap(1, 1)
Dim b As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(a)
b.CopyFromScreen(New Drawing.Point(MousePosition.X, MousePosition.Y), New Drawing.Point(0, 0), a.Size)
Dim c As Drawing.Color = a.GetPixel(0, 0)
PictureBox1.BackColor = c
Return PictureBox1.BackColor.Name
End Function