Peter
Peter

Reputation: 33

Checking RGB color value in C#?

I am very new to C# and couldn't find any information on the color type online. Sorry if this is a poorly worded question.

I am trying to make an if statement that checks if the RGB value of a part in a color array is a certain color but I'm not exactly sure how to go about it. Basically what I want to do is this:

if(color[100, 100] = RGB Color 255, 0, 0)
{
    //Do something
}

Upvotes: 0

Views: 2449

Answers (2)

Flipster
Flipster

Reputation: 4401

That code in c# would be:

if (color[100, 100] == Color.FromARGB(255, 0, 0))
{
    //do something...
}

The Color.FromARGB() method also has an overload where the first parameter accepts an alpha opacity level from 0-255, but you probably won't need that.

The code above assumes that your color[,] array actually contains an array of colors, of course.

Upvotes: 9

Harvey Kwok
Harvey Kwok

Reputation: 11873

Are you looking for System.Drawing.Color?

Upvotes: 1

Related Questions