Solved

Color transformation algorithm?

Posted on 2009-04-28
483 Views
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!
0
Question by:redflair
1 Comment

LVL 3

Accepted Solution

I found a VB code which does color degradation of any given two colors http://www.developerfusion.com/code/2150/creating-color-degradations-with-any-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);

}

return colors;

}
``````
0

Featured Post

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":…