public sd2.PathGradientBrush GetBrush(RectangleF rect) { var scale = 1f; var bounds = rect; if (Matrix != null) { bounds = Matrix.Inverse().TransformRectangle(bounds); } scale = GradientHelper.GetRadialScale(Center, Radius, GradientOrigin, bounds); if (brush == null || lastScale != scale) { lastScale = scale; var scaledRect = new RectangleF(GradientOrigin - (GradientOrigin - Center + Radius) * scale, GradientOrigin + (Center + Radius - GradientOrigin) * scale); var path = new sd2.GraphicsPath(); path.AddEllipse(scaledRect.ToSD()); brush = new sd2.PathGradientBrush(path); brush.CenterColor = StartColor.ToSD(); brush.CenterPoint = GradientOrigin.ToSD(); brush.WrapMode = wrapMode.ToSD(); brush.SurroundColors = new[] { EndColor.ToSD() }; if (Matrix != null) { brush.MultiplyTransform(Matrix.ToSD()); } if (scale > 1f) { var paths = GradientHelper.GetGradientStops(StartColor.ToSD(), EndColor.ToSD(), scale, wrapMode); brush.InterpolationColors = new sd2.ColorBlend { Positions = paths.Reverse().Select(r => 1f - r.Item1).ToArray(), Colors = paths.Reverse().Select(r => r.Item2).ToArray() }; } } return(brush); }