Blend colors with GDI+
In order to blend the two colors using a specified number of stages I decrees the color amount of the start color and increes it for the end color. I do this for each RGB channel. Here is my GDI+ color blender:C# .NET
private Color[] BlendColors(Color start, Color end, int steps)
{
Color[] colorPalette = new Color[steps];
double colorFactor = 100 / Convert.ToDouble(steps) / 100;
for (int colorLevel = 0; colorLevel < steps; colorLevel++)
{
double endColorQuantity = (colorLevel + 1) * colorFactor;
double startColorQuantity = 1 - endColorQuantity;
colorPalette[colorLevel] = Color.FromArgb(255,
Math.Abs(Convert.ToInt32(end.R * endColorQuantity + start.R * startColorQuantity)),
Math.Abs(Convert.ToInt32(end.G * endColorQuantity + start.G * startColorQuantity)),
Math.Abs(Convert.ToInt32(end.B * endColorQuantity + start.B * startColorQuantity)));
}
return colorPalette;
}
No comments:
Post a Comment