1

我有一个网格,其中包含标记有不同优先级的行。我想将高优先级的行染成红色,低优先级的行染成蓝色等。

我想根据数学计算的渐变设置阴影,而不是随意将颜色分配给特定的优先级。如何从沿渐变的单个点提取单一颜色?

4

1 回答 1

2

像这样的东西怎么样

VB.Net

Private Shared Function ColorGradientRedToBlue(ByVal index As Single) As Color
    If index < 0 OrElse index > 1.0R Then
        Throw New ArgumentException("index must be between 0 and 1")
    End If
    Return Color.FromArgb(CInt(((1.0R - index) * 255)), 0, CInt((index * 255)))
End Function

C#

static Color ColorGradientRedToBlue(float index)
{
    if (index < 0 || index > 1.0)
        throw new ArgumentException("index must be between 0 and 1");
    return Color.FromArgb((int)((1.0 - index) * 255), 0 ,(int)(index * 255));
}
于 2010-04-20T16:44:31.213 回答