Get a combination of two colors in .NET.

I have two colors in my .NET application that are user defined. I would like to somehow get a color between these two colors. This is the color in the middle of the gradient. Is there any way to do this?

+3
source share
4 answers

Well, the easiest way is to take the average value for each of the red, green, blue and alpha values:

Color c1 = ...;
Color c2 = ...;
Color midpoint = Color.FromArgb((c1.A + c2.A) / 2,
                                (c1.R + c2.R) / 2,
                                (c1.G + c2.G) / 2,
                                (c1.B + c2.B) / 2);

, A, R, G B , ints , . [0, 255], FromArgb Int32, , 8 - , .

(, HSV), . .

+14

- , :

, ( R, G, B), .

, , .

+8

By color, do you mean a Colorstruct instance ?

If so, just take all the components R, Gand Btake turns and calculate the average value for each. Combine the result to get a mixed color.

+6
source
CByte((CInt(byte1) + CInt(byte2)) \ 2)
+2
source

Source: https://habr.com/ru/post/1722814/


All Articles