public static BandValueColorPair[] SamplesBandValueColors(BandValueColorPair[] allValueColors, int count, out float span) { span = -1; if (allValueColors == null || allValueColors.Length == 0) { return(null); } if (count > allValueColors.Length) { count = allValueColors.Length; } BandValueColorPair[] rets = new BandValueColorPair[count]; if (count == 1) { rets[0] = allValueColors[0]; return(rets); } span = allValueColors.Length / (float)(count - 1); for (int i = 0; i < count; i++) { int idx = (int)(i * span); if (idx >= allValueColors.Length) { idx = allValueColors.Length - 1; } rets[i] = allValueColors[idx]; } return(rets); }
/// <summary> /// 最大取255种 /// </summary> /// <param name="bandValueColorPair"></param> /// <returns></returns> private ColorMapTable <double> ToColorMapTable(BandValueColorPair[] bandValueColorPair) { if (bandValueColorPair == null) { return(null); } ColorMapTable <double> ranges = new ColorMapTable <double>(); int maxCount = Math.Min(bandValueColorPair.Length, 254); for (int i = 0; i < maxCount; i++) //foreach (BandValueColorPair v in bandValueColorPair) { BandValueColorPair v = bandValueColorPair[i]; //[min,max) ranges.Items.Add(new ColorMapItem <double>(v.MinValue, v.MinValue == v.MaxValue ? v.MaxValue : v.MaxValue + 1, Color.FromArgb(v.Color.R, v.Color.G, v.Color.B))); } return(ranges); }