tomet
tomet

Reputation: 2556

RGB-Value to int

I've got a fairly simple problem (I hope):

I have a color:

Color c = Color.FromArgb(100, 150, 200);

And now I want to store say the R-Value of this color in an integer.

I tried to find this on google but I didn't really know what to search for. So I hope anyone can tell hwhat I need here.

Thank you in advance

Upvotes: 0

Views: 4411

Answers (3)

xqterry
xqterry

Reputation: 642

Is this what you need ?

RGBA (255, 255, 255, 255) = rgba( 1.0, 1.0, 1.0, 1.0) = 0xFFFFFFFF

Color.R = Color.G = Color.B = Color.A = 255 = 1.0 = 0xff

Upvotes: 0

Guffa
Guffa

Reputation: 700152

The R, G and B properties gives you the color components of the Color value. The compontent values are bytes, so you can assign one to an int variable without problems:

Color c = Color.FromArgb(100, 150, 200);
int red = c.R; // will be 100

Upvotes: 1

Oded
Oded

Reputation: 498904

The value will be accessible from the R member of Color: Color.R. In the same way the G will get the green value, B the blue and A the alpha.

These are bytes, so you can always cast to int if needed.

Upvotes: 4

Related Questions