使用LinearGradientBrush听起来会有一点开销.虽然没有知识.虽然颜色插值功能并不难写.
我假设您的调色板具有可以被10整除的值以简化.
public static Color GetColor(int value)
{
int startIndex = (value/10)*10;
int endIndex = startIndex + 10;
Color startColor = Palette[startIndex];
Color endColor = Palette[endIndex];
float weight = (value - startIndex)/(float)(endIndex - startIndex);
return Color.FromArgb(
(int)Math.Round(startColor.R * (1 - weight) + endColor.R * weight),
(int)Math.Round(startColor.G * (1 - weight) + endColor.G * weight),
(int)Math.Round(startColor.B * (1 - weight) + endColor.B * weight));
}
Run Code Online (Sandbox Code Playgroud)
如果定义的颜色不能被10整除,那么找到开始和结束颜色的逻辑将会更复杂一些.