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

  • SEARCH
  • Home
  • 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 7076579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:18:55+00:00 2026-05-28T06:18:55+00:00

On a form I have a PictureBox , a button to load image in

  • 0

On a form I have a PictureBox, a button to load image in the picturebox and couple of more buttons to do some operations on the image loaded into the picturebox.

I load a bitmap image into the picturebox and then I want to perform some operation on pixel ranges rgb(150,150,150) to rgb(192,222,255) of the loaded image.

  • Is it possible to do this using SetPixel method?
  • Is there any way to specify a range of RGB values in C#?
  • 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-05-28T06:18:56+00:00Added an answer on May 28, 2026 at 6:18 am

    Simple way would be something like this:

    for (int i = 0; i < width; i++)
       for (int j = 0; j < height; j++)
       {
           Color c = bitmap.GetPixel(i, j);
           if (ColorWithinRange(c))
           {
               // do stuff
           }
       }
    

    With ColorWithinRange defined like this:

    private readonly Color _from = Color.FromRgb(150, 150, 150);
    private readonly Color _to = Color.FromRgb(192, 222, 255);
    bool ColorWithinRange(Color c)
    {
       return 
          (_from.R <= c.R && c.R <= _to.R) &&
          (_from.G <= c.G && c.G <= _to.G) &&
          (_from.B <= c.B && c.B <= _to.B);
    }
    

    For large bitmap sizes, however, GetPixel and SetPixel become very slow. So, after you have implemented your algorithm, if it feels slow, you can use the Bitmap.LockBits method to pin the bitmap (prevent GC from moving it around memory) and allow yourself fast unsafe access to individual bytes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pictureBox on a Windows Form. I do the following to load
I have a PictureBox on a form. In Load event of the form I
I have a picturebox on the form, with BackgroundImage property set to certain image.
I have a form with a picturebox which displays a picture and some overlay
hi i have picturebox with displaying image when i click on button its fine...
i have picturebox control in my form that SizeMode = StretchImage when i load
I have a PictureBox control on a Form that is supposed to draw something
I have form area in my view. If I click button A , I
i have form action file in another directory but some file send to this
I have form with one input for email and two submit buttons to subscribe

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.