Color transformation algorithm?

Posted on 2009-04-28
Last Modified: 2013-11-19
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!
Question by:redflair
    1 Comment
    LVL 3

    Accepted Solution

    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


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
    Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
    In this second Micro Tutorial in the series,  viewers will learn more basic shortcuts and functions of Illustrator. In this tutorial you will learn about the eyedropper tool, zoom , ellipses and more.
    Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now