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:![Blend colors with GDI+](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfP9Ql8NSUsPZPzzJqTNoGjUthYdY1c6OdBI-cXVDqQSZwQCwj_9gew1Uem1iKzs625hWZdOCAA5-LjhvLgwqSEAgHUWfCvfPjAv6GK9MJbZYU9d267s8CfiLr5EmX5rA9HMx22-ndC47b/s200/Blend_Colors.jpg)
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