Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:24:44+00:00 2026-06-14T18:24:44+00:00

In my code I get the pixel color of a given coordinate and I

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:24:46+00:00Added an answer on June 14, 2026 at 6:24 pm

    I’d create a function like this and make a call to it with both colors:

    Private Function CompareColors(ByVal Color1 As Color, ByVal Color2 As Color) As Boolean
        If Color1.ToArgb = Color2.ToArgb Then
            'perfect match
            Return True
        ElseIf Asc(Color1.R) > Asc(Color2.R) - 10 AndAlso Asc(Color1.R) < Asc(Color2.R) + 10 Then
            ' red is wrong
            Return False
        ElseIf Asc(Color1.G) > Asc(Color2.G) - 10 AndAlso Asc(Color1.G) < Asc(Color2.G) + 10 Then
            ' green is wrong
            Return False
        ElseIf Asc(Color1.B) > Asc(Color2.B) - 10 AndAlso Asc(Color1.B) < Asc(Color2.B) + 10 Then
            ' blue is wrong
            Return False
        ElseIf Asc(Color1.A) > Asc(Color2.A) - 10 AndAlso Asc(Color1.A) < Asc(Color2.A) + 10 Then
            ' alpha is wrong
            Return False
        Else
            Return True
        End If
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set a color of given pixel of the image. Here is
I need to get the color of pixel under mouse, inside mouseMoveEvent of a
I am trying to get the color of a pixel in JOGL when the
Why does the following code get the runtime error: Members of the Triggers collection
I have the following code: // GET: /PlayRoundHole/Create public ActionResult Create(int id) { DB
here is my code:(get file line num and word count) import System.IO import Data.Maybe
When I run this C code: // Get rid of the CRT and stuff;
Consider the following snippet of code: // get number of sheep in DataTable by
I'm currently using the following PHP code: // Get all subordinates $subords = array();
I'm trying to understand why my code get stuck in the for loop of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.