I have two colors in my .NET application that are user defined. I’d like to somehow get the color in between those two colors. It’s the color in the middle of the gradient. Is there any way to accomplish this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Well, the simplest way is to take the average of each of the red, green, blue and alpha values:
Even though the A, R, G and B properties are bytes, they’ll be promoted to ints before addition, so there won’t be an overflow problem. The result of the division will still be in the range [0, 255] and
FromArgbtakesInt32values but discards everything other than the lowest 8 bits – just what we want.An alternative would be to use a different colour model (e.g. HSV) but that would be somewhat more complicated. For gradients, this should do fine.