Exemplo n.º 1
0
        public Color Lookup(double value)
        {
            int startId = LookupSegment(0, colorMap_.Count - 1, value);
            int endId   = startId + 1;

            if (startId == -1)
            {
                return(colorMap_[0].Color);
            }
            if (endId == colorMap_.Count)
            {
                return(colorMap_[endId - 1].Color);
            }

            //线性插值一下
            ColorValuePair startCV = colorMap_[startId];
            ColorValuePair endCV   = colorMap_[endId];
            double         t       = 0.5;

            if (Math.Abs(startCV.Value - endCV.Value) > float.Epsilon)
            {
                t = (endCV.Value - value) / (endCV.Value - startCV.Value);
            }
            double one_t = 1.0 - t;

            return(Color.FromArgb(
                       (int)(startCV.Color.R * t + endCV.Color.R * one_t),
                       (int)(startCV.Color.G * t + endCV.Color.G * one_t),
                       (int)(startCV.Color.B * t + endCV.Color.B * one_t)
                       ));
        }
Exemplo n.º 2
0
        public ColorMap GenerateLinearColorMap(Color fromColor, Color toColor, double min, double max)
        {
            List <ColorValuePair> cMap = new List <ColorValuePair>(
                new ColorValuePair[] { ColorValuePair.Create(fromColor, min), ColorValuePair.Create(toColor, max) }
                );

            return(new LinearColorMap(cMap));
        }