c#rgb色标

时间:2010-12-02 12:34:34

标签: c# rgb

我需要根据数据显示特定的颜色表示。比例的一端是绿色,另一端是红色。比例应覆盖其间的颜色。

我对实际编程很满意,但不确定如何缩放rgb颜色。有没有人知道这种事情的任何尺度?

感谢。

3 个答案:

答案 0 :(得分:6)

以下方法适用于您:

    Color GetColor(Int32 rangeStart /*Complete Red*/, Int32 rangeEnd /*Complete Green*/, Int32 actualValue)
    {
        if (rangeStart >= rangeEnd) return Colors.Black;

        Int32 max = rangeEnd - rangeStart; // make the scale start from 0
        Int32 value = actualValue - rangeStart; // adjust the value accordingly

        Int32 green = (255 * value) / max; // calculate green (the closer the value is to max, the greener it gets)
        Int32 red = 255 - green; // set red as inverse of green

        return Color.FromRgb((Byte)red, (Byte)green, (Byte)0);
    }

答案 1 :(得分:4)

这是你的意思吗?

Color GetColor(int scale)
{
    // scale is between 1 and 255
    return Color.FromArgb(255, scale, 255 - scale, 0);
}

答案 2 :(得分:2)

除了线性刻度之外,您可能会发现通过一点颜色理论可以更清楚地获得信息。根据您想花多少时间,您可能还需要查看例如。

Cynthia Brewer

Adobe Kuler

Stanford lecture on Colour for visualization

其中许多人 - 谷歌也在处理和数据可视化。