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 9301369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:59:59+00:00 2026-06-18T22:59:59+00:00

I have a .NET BitmapSource object. I would like to read the four pixels

  • 0

I have a .NET BitmapSource object. I would like to read the four pixels in corners of the bitmap, and test whether all of them are darker than white. How can I do that?

Edit: I wouldn’t mind converting this object to another type with a better API.

  • 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-18T23:00:00+00:00Added an answer on June 18, 2026 at 11:00 pm

    BitmapSource has a CopyPixels method that can be used to get one or more pixel values.

    A helper method that gets a single pixel value at a given pixel coordinate may look like shown below. Note that it perhaps has to be extended to support all required pixel formats.

    public static Color GetPixelColor(BitmapSource bitmap, int x, int y)
    {
        Color color;
        var bytesPerPixel = (bitmap.Format.BitsPerPixel + 7) / 8;
        var bytes = new byte[bytesPerPixel];
        var rect = new Int32Rect(x, y, 1, 1);
    
        bitmap.CopyPixels(rect, bytes, bytesPerPixel, 0);
    
        if (bitmap.Format == PixelFormats.Bgra32)
        {
            color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
        }
        else if (bitmap.Format == PixelFormats.Bgr32)
        {
            color = Color.FromRgb(bytes[2], bytes[1], bytes[0]);
        }
        // handle other required formats
        else
        {
            color = Colors.Black;
        }
    
        return color;
    }
    

    You would use the method like this:

    var topLeftColor = GetPixelColor(bitmap, 0, 0);
    var topRightColor = GetPixelColor(bitmap, bitmap.PixelWidth - 1, 0);
    var bottomLeftColor = GetPixelColor(bitmap, 0, bitmap.PixelHeight - 1);
    var bottomRightColor = GetPixelColor(bitmap, bitmap.PixelWidth - 1, bitmap.PixelHeight - 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have .NET application and would like to allow users to write macros. Any
i have .net 3.5 and i would like to make a generic method. how
In case I have .NET framework installed in my computer + all the necessary
Does .Net have any built in constants for common numbers like million, billion etc?
Does .net have the equivilent of Delphi's QuotedStr function. This replaces all quotes with
In the bank I work all client workstations have .Net 2 installed it is
If I have .Net Form with a component/object such as a textbox that I
If the end user dont have .net 4.0 installed , i dont want them
I have .net console application and com object I want to instantiate via: var
In C# we have .Net class and the short names, like Double and double.

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.