Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Finding if an area of an image is black


I'm looking for some C# code that will let me test a small section of a System.Drawing.Image (or a bitmap) to see if it is black - sometimes, when I take a screen capture of a window, it doesn't paint properly and parts of the image are black. I want to be able to test if a part that shouldn't be black is black or not.
1 Solution
Carl TawnSystems and Integration DeveloperCommented:
You can use something like:

            Image img = Image.FromFile("C:\\Test.bmp");
            Bitmap bmp = new Bitmap(i);
            if (bmp.GetPixel(0, 0).ToArgb() == Color.Black.ToArgb())
                MessageBox.Show("Pixel is black");

To test individual pixels. This sample tests the pixel in the upper left corner (0, 0).
saltedAuthor Commented:
Perfect, thanks :)

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now