In my code I get the pixel color of a given coordinate and I then check to see if that color matches another color. It works great, now I want to be able to check if it matches within 10 or so shades of the color or a set amount of shades. I have no idea how to do this though. Here is the code:
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
I’d create a function like this and make a call to it with both colors: