public static void Draw(this RadialGradient target, CGContext ctx, CGRect bounds) { target.Update(); CGRect clippingBounds = bounds; if (!target.Frame.IsEmpty) { bounds = new CGRect(target.Frame.X, target.Frame.Y, target.Frame.Width, target.Frame.Height); } var gradColors = GenerateGradientColors(target.Colors); var colorSpace = CGColorSpace.CreateDeviceRGB(); var grad = new CGGradient(colorSpace, gradColors, ConvertToNativeArray(target.Locations)); var gradCenter = new CGPoint((bounds.Width * target.Center.X), (bounds.Height * target.Center.Y)); var gradRadius = (nfloat)Math.Min(bounds.Size.Width / 2, bounds.Size.Height / 2); var drawingFlags = GetGradientFlags(target); var scaleT = CGAffineTransform.MakeScale(target.Scale.X, target.Scale.Y); ctx.SaveState(); if (!target.Frame.IsEmpty) { ctx.ClipToRect(new CGRect(bounds.X + clippingBounds.X, bounds.Y + clippingBounds.Y, clippingBounds.Width, clippingBounds.Height)); } ctx.TranslateCTM(bounds.X + gradCenter.X, bounds.Y + gradCenter.Y); ctx.ScaleCTM(scaleT.xx, scaleT.yy); ctx.DrawRadialGradient(grad, CGPoint.Empty, 0, CGPoint.Empty, gradRadius, drawingFlags); ctx.RestoreState(); grad.Dispose(); colorSpace.Dispose(); }
public static Shader Draw(this RadialGradient target, PointF position, float radius) { target.Update(); var grad = new Android.Graphics.RadialGradient( position.X, position.Y, radius, target.Colors.ToInt(), target.Locations, Shader.TileMode.Clamp ); return(grad); }