在我的代码中,我获取给定坐标的像素颜色,然后检查该颜色是否与另一种颜色匹配。它效果很好,现在我希望能够检查它是否在 10 种左右的颜色或一定数量的色调范围内匹配。我不知道该怎么做。这是代码:
Public Function GetPixelColor(ByVal x As Integer, ByVal y As Integer) As Color
Dim sz As New Size(1, 1)
Dim c As Color
Using bmp As New Bitmap(1, 1)
Using g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(New Point(x, y), Point.Empty, sz)
c = bmp.GetPixel(0, 0)
End Using
End Using
Return c
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fb As Color = GetPixelColor(TextBox1.Text, TextBox2.Text)
If fb.ToArgb() = TextBox3.Text Then
MessageBox.Show("Rock on dude")
End If
End Sub