private static Color GetColorByOffset(GradientStopCollection collection, double offset) { GradientStop[] stops = collection.OrderBy(x => x.Offset).ToArray(); if (offset <= 0) { return(stops[0].Color); } if (offset >= 1) { return(stops[stops.Length - 1].Color); } GradientStop left = stops[0], right = null; foreach (GradientStop stop in stops) { if (stop.Offset >= offset) { right = stop; break; } left = stop; } offset = Math.Round((offset - left.Offset) / (right.Offset - left.Offset), 2); byte a = (byte)((right.Color.A - left.Color.A) * offset + left.Color.A); byte r = (byte)((right.Color.R - left.Color.R) * offset + left.Color.R); byte g = (byte)((right.Color.G - left.Color.G) * offset + left.Color.G); byte b = (byte)((right.Color.B - left.Color.B) * offset + left.Color.B); return(Color.FromArgb(a, r, g, b)); }
internal static Color GetColorAtOffset(this GradientStopCollection collection, double offset) { var stops = collection.OrderBy(x => x.Offset).ToArray(); if (offset <= 0) { return(stops[0].Color); } else if (offset >= 1) { return(stops[stops.Length - 1].Color); } var left = stops[0]; GradientStop right = null; foreach (var stop in stops) { if (stop.Offset >= offset) { right = stop; break; } left = stop; } var percent = Math.Round((offset - left.Offset) / (right.Offset - left.Offset), 3); var a = (byte)((right.Color.A - left.Color.A) * percent + left.Color.A); var r = (byte)((right.Color.R - left.Color.R) * percent + left.Color.R); var g = (byte)((right.Color.G - left.Color.G) * percent + left.Color.G); var b = (byte)((right.Color.B - left.Color.B) * percent + left.Color.B); return(Color.FromArgb(a, r, g, b)); }
private void calculateColor() { GradientStop[] stops = gradientStopCollection.OrderBy(_gradientStopCollection => _gradientStopCollection.Offset).ToArray(); if (offset <= 0) { bgr[0] = stops[0].Color.B; bgr[1] = stops[0].Color.G; bgr[2] = stops[0].Color.R; return; } if (offset >= 1) { bgr[0] = stops[stops.Length - 1].Color.B; bgr[1] = stops[stops.Length - 1].Color.G; bgr[2] = stops[stops.Length - 1].Color.R; return; } GradientStop left = stops[0], right = null; foreach (GradientStop stop in stops) { if (stop.Offset >= offset) { right = stop; break; } left = stop; } offset = (float)Math.Round((offset - left.Offset) / (right.Offset - left.Offset), 2); bgr[0] = (byte)((right.Color.B - left.Color.B) * offset + left.Color.B); bgr[1] = (byte)((right.Color.G - left.Color.G) * offset + left.Color.G); bgr[2] = (byte)((right.Color.R - left.Color.R) * offset + left.Color.R); return; }
private void SetSortGaudeGradient(GradientStopCollection AUnsortCollection) { if (AUnsortCollection != null) { FSortGaudeGradient = AUnsortCollection.OrderBy(gs => gs.Offset).ToArray(); RecreateGridCells(); } }
/// <inheritdoc /> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { GradientStopCollection collection = (GradientStopCollection)value; List <ColorGradientStop> colorGradients = new(); if (collection == null) { return(colorGradients); } foreach (GradientStop c in collection.OrderBy(s => s.Offset)) { colorGradients.Add(new ColorGradientStop(new SKColor(c.Color.R, c.Color.G, c.Color.B, c.Color.A), (float)c.Offset)); } return(colorGradients); }
public static Color GetColorByOffset(GradientStopCollection collection, double offset) { var stops = collection.OrderBy(x => x.Offset).ToArray(); if (offset <= 0) { return(stops[0].Color); } if (offset >= 1) { return(stops[stops.Length - 1].Color); } var left = stops.Where(s => s.Offset <= offset).Last(); var right = stops.Where(s => s.Offset > offset).First(); offset = Math.Round((offset - left.Offset) / (right.Offset - left.Offset), 2); var a = (byte)((right.Color.A - left.Color.A) * offset + left.Color.A); var r = (byte)((right.Color.R - left.Color.R) * offset + left.Color.R); var g = (byte)((right.Color.G - left.Color.G) * offset + left.Color.G); var b = (byte)((right.Color.B - left.Color.B) * offset + left.Color.B); return(Color.FromArgb(a, r, g, b)); }