Color transformation algorithm?

Hello Experts,

I am looking for an algorithm which would have to generate specified number of color variances between the two given colors.

For eg., If I say RGB(200,240,233) and RGB(10,40,255) are the colors, and 10 as variances then I would expect the algorithm to produce 10 color codes to indicate the color transformation from RGB(200,240,233) to RGB(10,40,255).

I am not sure if .NET has built-in function for this, if so please point it out.

Thank you!
Who is Participating?
redflairConnect With a Mentor Author Commented:
I found a VB code which does color degradation of any given two colors Converted to C# and it works pretty good.
        public static List<Color> CalculateGradient(Color color1, Color color2, int steps)
            List<Color> colors = new List<Color>(steps);
            for (int i=0; i<steps; i++)
                Int64 tRed = color1.R + Math.Sign(Convert.ToInt64(color2.R) - Convert.ToInt64(color1.R)) * Convert.ToByte(Math.Abs(Convert.ToInt64(color2.R) - Convert.ToInt64(color1.R)) / (steps) * i);
                Int64 tGreen = color1.G + Math.Sign(Convert.ToInt64(color2.G) - Convert.ToInt64(color1.G)) * Convert.ToByte(Math.Abs(Convert.ToInt64(color2.G) - Convert.ToInt64(color1.G)) / (steps) * i);
                Int64 tBlue = color1.B + Math.Sign(Convert.ToInt64(color2.B) - Convert.ToInt64(color1.B)) * Convert.ToByte(Math.Abs(Convert.ToInt64(color2.B) - Convert.ToInt64(color1.B)) / (steps) * i);                
                colors.Add(Color.FromRgb(Convert.ToByte(tRed), Convert.ToByte(tGreen), Convert.ToByte(tBlue)));
            return colors;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.