VB.Net 与 Autoit 类似的颜色变化
VB.Net Color Variation like in Autoit
我有一个简单的像素搜索功能,可以在屏幕上搜索特定的 Argb 颜色。
这已经很好用了,它找到了带有颜色的像素,但我想给它添加一个颜色变化检测。
它应检测的像素颜色有时会从 (255, 100, 100, 100) 变为 (255, 110, 94, 102) 或其他值(值变化 10 点)。现在 Pixelsearch 函数应该有一个 Variationdetection 以便它可以检测具有接近相似颜色的像素,所以它不仅应该搜索颜色 (255, 100, 100, 100),还应该搜索 (255, 101, 99, 102).. .还有更多
是否可以编码而不是调暗每种颜色并搜索它?
这就是我已有的代码:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim xd3 = Color.FromArgb(255, 100, 100, 100) 'Searching for this color on the screen
Dim b As New Bitmap(2210, 1100) 'Position of Bitmap
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(b)
g.CopyFromScreen(Me.Left, Me.Top, 0, 0, b.Size) 'Searching on Screen
For i = 0 To (Me.Width - 0) 'searching each pixel
For j = 0 To (Me.Height - 0) 'searching each pixel
If b.GetPixel(i, j) = xd3 Then 'If pixel has same color that im searching for it will show a messagebox true
MessageBox.Show("true")
End If
Next
Next
End Sub
我建议这样:
If Color_Is_In_The_Target_Variations(10, b.GetPixel(i, j), xd3) Then
MessageBox.Show("true")
End If
和
Private Function Color_Is_In_The_Target_Variations(variation As Integer, tested As Color, target As Color) As Boolean
If tested.R >= target.R - variation And tested.R <= target.R + variation And
tested.G >= target.G - variation And tested.G <= target.G + variation And
tested.B >= target.B - variation And tested.B <= target.B + variation Then
Return True
Else
Return False
End If
End Function
我有一个简单的像素搜索功能,可以在屏幕上搜索特定的 Argb 颜色。 这已经很好用了,它找到了带有颜色的像素,但我想给它添加一个颜色变化检测。
它应检测的像素颜色有时会从 (255, 100, 100, 100) 变为 (255, 110, 94, 102) 或其他值(值变化 10 点)。现在 Pixelsearch 函数应该有一个 Variationdetection 以便它可以检测具有接近相似颜色的像素,所以它不仅应该搜索颜色 (255, 100, 100, 100),还应该搜索 (255, 101, 99, 102).. .还有更多
是否可以编码而不是调暗每种颜色并搜索它?
这就是我已有的代码:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim xd3 = Color.FromArgb(255, 100, 100, 100) 'Searching for this color on the screen
Dim b As New Bitmap(2210, 1100) 'Position of Bitmap
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(b)
g.CopyFromScreen(Me.Left, Me.Top, 0, 0, b.Size) 'Searching on Screen
For i = 0 To (Me.Width - 0) 'searching each pixel
For j = 0 To (Me.Height - 0) 'searching each pixel
If b.GetPixel(i, j) = xd3 Then 'If pixel has same color that im searching for it will show a messagebox true
MessageBox.Show("true")
End If
Next
Next
End Sub
我建议这样:
If Color_Is_In_The_Target_Variations(10, b.GetPixel(i, j), xd3) Then
MessageBox.Show("true")
End If
和
Private Function Color_Is_In_The_Target_Variations(variation As Integer, tested As Color, target As Color) As Boolean
If tested.R >= target.R - variation And tested.R <= target.R + variation And
tested.G >= target.G - variation And tested.G <= target.G + variation And
tested.B >= target.B - variation And tested.B <= target.B + variation Then
Return True
Else
Return False
End If
End Function