Finding if an area of an image is black

Posted on 2006-04-16
Last Modified: 2012-08-13

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.
Question by:salted
    LVL 52

    Accepted Solution

    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).

    Author Comment

    Perfect, thanks :)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now