private void DrawBorder(CGContext ctx) { if (!HasBorder()) { return; } if (IsBorderDashed()) { ctx.SetLineDash(0, new [] { (nfloat)_dashWidth, (nfloat)_dashGap }); } // Stroke is inner, the outer will be clipped. So double the value to get the real one! ctx.SetLineWidth(2 * _strokeWidth); ctx.AddPath(GetRoundCornersPath(Bounds).CGPath); if (HasBorderGradient()) { ctx.ReplacePathWithStrokedPath(); ctx.Clip(); var startPoint = new CGPoint(_strokePositions[0] * Bounds.Width, _strokePositions[1] * Bounds.Height); var endPoint = new CGPoint(_strokePositions[2] * Bounds.Width, _strokePositions[3] * Bounds.Height); var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), _strokeColors, _strokeColorPositions); ctx.DrawLinearGradient(gradient, startPoint, endPoint, CGGradientDrawingOptions.None); } else if (_strokeColor != null) { ctx.SetStrokeColor(_strokeColor.CGColor); ctx.DrawPath(CGPathDrawingMode.Stroke); } }
public static UIImage MakeBlueSea() { UIGraphics.BeginImageContext(new System.Drawing.SizeF(640,1136)); //BEGIN PAINTCODE //// General Declarations var colorSpace = CGColorSpace.CreateDeviceRGB(); var context = UIGraphics.GetCurrentContext(); //// Color Declarations UIColor color = UIColor.FromRGBA(0.114f, 0.705f, 1.000f, 1.000f); UIColor gradientColor = UIColor.FromRGBA(0.088f, 0.606f, 0.676f, 1.000f); UIColor gradientColor2 = UIColor.FromRGBA(0.018f, 0.509f, 0.675f, 1.000f); //// Gradient Declarations var gradientColors = new CGColor [] {color.CGColor, UIColor.FromRGBA(0.066f, 0.607f, 0.837f, 1.000f).CGColor, gradientColor2.CGColor, gradientColor.CGColor}; var gradientLocations = new float [] {0, 0.21f, 0.46f, 1}; var gradient = new CGGradient(colorSpace, gradientColors, gradientLocations); //// Rectangle Drawing var rectanglePath = UIBezierPath.FromRect(new RectangleF(-46.5f, -35.5f, 728, 1192)); context.SaveState(); rectanglePath.AddClip(); context.DrawLinearGradient(gradient, new PointF(317.5f, -35.5f), new PointF(317.5f, 1156.5f), 0); context.RestoreState(); UIColor.Black.SetStroke(); rectanglePath.LineWidth = 1; rectanglePath.Stroke(); //END PAINTCODE var converted = UIGraphics.GetImageFromCurrentImageContext (); UIGraphics.EndImageContext (); return converted; }
private UIImage GetGradientImage(CGSize size) { var c1 = (Element as GradientLabel).TextColor1.ToCGColor(); var c2 = (Element as GradientLabel).TextColor2.ToCGColor(); UIGraphics.BeginImageContextWithOptions(size, false, 0); var context = UIGraphics.GetCurrentContext(); if (context == null) { return(null); } context.SetFillColor(UIColor.Blue.CGColor); context.FillRect(new RectangleF(new PointF(0, 0), new SizeF((float)size.Width, (float)size.Height))); var left = new CGPoint(0, 0); var right = new CGPoint(size.Width, 0); var colorspace = CGColorSpace.CreateDeviceRGB(); var gradient = new CGGradient(colorspace, new CGColor[] { c1, c2 }, new nfloat[] { 0f, 1f }); context.DrawLinearGradient(gradient, left, right, CGGradientDrawingOptions.DrawsAfterEndLocation); var img = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return(img); }
static MessageSummaryView () { using (var colorspace = CGColorSpace.CreateDeviceRGB ()) { gradient = new CGGradient (colorspace, new float [] { /* first */ .52f, .69f, .96f, 1, /* second */ .12f, .31f, .67f, 1 }, null); //new float [] { 0, 1 }); } }
public void OnSettingsLineRadarDataSet <TEntry>(ILineRadarDataSetXF <TEntry> baseDataSetXF, LineRadarChartDataSet originalBaseDataSet) where TEntry : BaseEntry { OnSettingsLineScatterCandleRadarDataSet(baseDataSetXF, originalBaseDataSet); if (baseDataSetXF.IF_GetGradientColor() != null) { var gradientData = baseDataSetXF.IF_GetGradientColor(); var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor[] { gradientData.StartColor.ToCGColor(), gradientData.EndColor.ToCGColor() }); originalBaseDataSet.Fill = ChartFill.FillWithLinearGradient(NSObject.FromObject(gradient), NSNumber.FromFloat(gradientData.Angle)); } if (baseDataSetXF.IF_GetFillColor().HasValue) { originalBaseDataSet.FillColor = baseDataSetXF.IF_GetFillColor().Value.ToUIColor(); } if (baseDataSetXF.IF_GetFillAlpha().HasValue) { originalBaseDataSet.FillAlpha = baseDataSetXF.IF_GetFillAlpha().Value; } if (baseDataSetXF.IF_GetLineWidth().HasValue) { originalBaseDataSet.LineWidth = baseDataSetXF.IF_GetLineWidth().Value; } if (baseDataSetXF.IF_GetDrawFilled().HasValue) { originalBaseDataSet.DrawFilledEnabled = baseDataSetXF.IF_GetDrawFilled().Value; } }
public override void Draw(RectangleF rect) { using (CGContext context = UIGraphics.GetCurrentContext()) { switch (_Style) { case SIAlertViewBackgroundStyle.Gradient: { float[] locations = { 0.0f, 1.0f }; float[] colors = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f }; CGGradient gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), colors, locations); PointF center = new PointF(Bounds.Size.Width / 2, Bounds.Size.Height / 2); float radius = Math.Min(Bounds.Size.Width, Bounds.Size.Height); context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation); break; } case SIAlertViewBackgroundStyle.Solid: { UIColor.FromWhiteAlpha(0f, 0.5f).SetColor(); context.SetFillColorWithColor(UIColor.FromWhiteAlpha(0f, 0.5f).CGColor); context.FillRect(Bounds); break; } } } }
public override void Draw(CGRect rect) { base.Draw(rect); var step = 1f / 6f; var locations = new nfloat[] { 0.0f, step * 1f, step * 2f, step * 3f, step * 4f, step * 5f, 1.0f }; var colors = new CGColor[] { UIColor.Red.CGColor, new CGColor(1, 0, 1, 1), UIColor.Blue.CGColor, new CGColor(0, 1, 1, 1), UIColor.Green.CGColor, new CGColor(1, 1, 0, 1), UIColor.Red.CGColor }; using (var colorSpace = CGColorSpace.CreateDeviceRGB()) using (var gradiend = new CGGradient(colorSpace, colors, locations)) { var context = UIGraphics.GetCurrentContext(); context.DrawLinearGradient(gradiend, new CGPoint(rect.Size.Width, 0), new CGPoint(0, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation); } }
public void DrawLayer(CALayer layer, CGContext context) { nfloat gradStart = .15f; if (BlinkingCountdown > 0) { BlinkingCountdown--; gradStart += .15f * ((nfloat)BlinkingCountdown / (BlinkCount - 1)); } var gradient = new CGGradient( CGColorSpace.CreateDeviceRGB(), new CGColor[] { DarkendedColor, Color }, new nfloat[] { gradStart, 1 } ); context.DrawRadialGradient( gradient, new CGPoint(layer.Frame.Width / 2, layer.Frame.Width / 2), Ring.InnerRadiusLocation, new CGPoint(layer.Frame.Width / 2, layer.Frame.Width / 2), Ring.OuterRadiusLocation, CGGradientDrawingOptions.None ); }
public static CGGradient CreateGradient(List <UIColor> colors, List <float> points) { List <nfloat> colorf = new List <nfloat>(); foreach (UIColor c in colors) { nfloat r, g, b, a; c.GetRGBA(out r, out g, out b, out a); colorf.Add(r); colorf.Add(g); colorf.Add(b); colorf.Add(a); } nfloat [] components = colorf.ToArray(); nfloat[] locations = new nfloat[points.Count]; for (int i = 0; i < points.Count; i++) { locations[i] = points[i]; } CGColorSpace space = CGColorSpace.CreateDeviceRGB(); CGGradient normalGradient = new CGGradient(space, components, locations); space.Dispose(); return(normalGradient); }
public override void Draw(RectangleF rect) { CGContext context = UIGraphics.GetCurrentContext(); switch (this.mask) { case SVProgressHUDMask.Black: { UIColor.FromWhiteAlpha(0f, 0.5f).SetColor(); context.FillRect(this.Bounds); break; } case SVProgressHUDMask.Gradient: { float[] locations = new float[2] { 0.0f, 1.0f }; float[] colors = new float[8] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f }; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); CGGradient gradient = new CGGradient(colorSpace, colors, locations); colorSpace.Dispose(); PointF center = new PointF(this.Bounds.Size.Width / 2f, this.Bounds.Size.Height / 2f); float radius = Math.Min(this.Bounds.Size.Width, this.Bounds.Size.Height); context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation); gradient.Dispose(); break; } } }
public void Draw(GraphicsHandler graphics, RectangleF rect) { var start = StartPoint; var end = EndPoint; if (transform != null) { start = transform.TransformPoint(start); end = transform.TransformPoint(end); } if (wrap == GradientWrapMode.Pad) { if (Gradient == null) { Gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new [] { StartColor, EndColor }, new nnfloat[] { (nnfloat)0f, (nnfloat)1f }); } } else { var scale = GradientHelper.GetLinearScale(ref start, ref end, rect, lastScale, wrap == GradientWrapMode.Reflect ? 2f : 1f); if (Gradient == null || scale > lastScale) { var stops = GradientHelper.GetGradientStops(StartColor, EndColor, scale, wrap).ToList(); Gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), stops.Select(r => r.Item2).ToArray(), stops.Select(r => (nnfloat)r.Item1).ToArray()); lastScale = scale; } } var context = graphics.Control; context.DrawLinearGradient(Gradient, start.ToNS(), end.ToNS(), CGGradientDrawingOptions.DrawsAfterEndLocation | CGGradientDrawingOptions.DrawsBeforeStartLocation); }
private static void DrawSeparator(CGContext canvas, nfloat pos, nfloat separatorWidth, nfloat startY, nfloat restY, UIColor color1) { canvas.SaveState(); canvas.SetLineWidth(0); var path = new CGPath(); //path.AddLines(points.ToArray()); path.AddLines(new[] { new CGPoint(pos, startY), new CGPoint(pos, startY + restY), new CGPoint(pos + separatorWidth, startY + restY), new CGPoint(pos + separatorWidth, startY) }); path.CloseSubpath(); canvas.AddPath(path); //canvas.FillRect(new CGRect(pos, startY, separatorWidth, restY)); canvas.Clip(); using (var rgb = CGColorSpace.CreateDeviceRGB()) { var gradient = new CGGradient(rgb, new[] { new CGColor(color1.CGColor, 0.25f), new CGColor(color1.CGColor, 0.5f) }); canvas.DrawLinearGradient(gradient, //new CGPoint(path.BoundingBox.Left, path.BoundingBox.Top), //new CGPoint(path.BoundingBox.Right, path.BoundingBox.Bottom), new CGPoint(0, startY), new CGPoint(0, startY + restY), CGGradientDrawingOptions.DrawsBeforeStartLocation); } canvas.RestoreState(); }
public override void Draw(CGRect rect) { base.Draw(rect); CGGradient gradient = null; using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) { gradient = new CGGradient(rgb, new CGColor[] { _startColor.ToCGColor(), _middleColor.ToCGColor(), _endColor.ToCGColor() }); } var start = new CGPoint(0, 0); var end = new CGPoint(rect.Width, rect.Height); for (var i = 0; i < Subviews.Length; i++) { var child = Subviews[i]; if (child is FrameRenderer_iOS gFrame) { gFrame.Gradient = gradient; gFrame.Start = start; gFrame.End = end; } } }
public override void Draw(CGRect rect) { using (var context = UIGraphics.GetCurrentContext()) { switch (_maskType) { case MaskType.Black: UIColor.FromWhiteAlpha(0f, 0.5f).SetColor(); context.FillRect(Bounds); break; case MaskType.Gradient: nfloat[] colors = new nfloat[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f }; nfloat[] locations = new nfloat[] { 0.0f, 1.0f }; using (var colorSpace = CGColorSpace.CreateDeviceRGB()) { using (var gradient = new CGGradient(colorSpace, colors, locations)) { var center = new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height / 2); float radius = Math.Min((float)Bounds.Size.Width, (float)Bounds.Size.Height); context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation); } } break; } } }
public override void DrawInContext(CGContext ctx) { base.DrawInContext(ctx); //Debug.WriteLine($"---{this.Radius}"); //每四个一组 表示一个颜色 {r,g,b,a ,r,g,b,a} //var components = new nfloat[] { 1, 1, 1, 1, 1, 1, 1, 0 }; var colors = new CGColor[] { new CGColor(0.49f, 0.49f, 0.49f, 0.5f), new CGColor(0.78f, 0.78f, 0.78f, 0.2f), }; //表示渐变的开始位置 var locations = new nfloat[] { 0f, 1f }; var startCenter = this.Center;//new CGPoint(100, 100); var endCenter = this.Center;//new CGPoint(100, 100); nfloat startRadius = 0f; //nfloat endRadius = (nfloat)Math.Min(this.Frame.Width, this.Frame.Height) / 1.3f; nfloat endRadius = this.Radius; using (var colorSpace = CGColorSpace.CreateDeviceRGB()) using (var gradient = new CGGradient(colorSpace, colors, locations)) { ctx.DrawRadialGradient(gradient, startCenter, startRadius, endCenter, endRadius, CGGradientDrawingOptions.DrawsAfterEndLocation); } }
//Generated with PaintCode 2.2 public override void Draw(CGRect rect) { base.Draw(rect); // General Declarations var colorSpace = CGColorSpace.CreateDeviceRGB(); var context = UIGraphics.GetCurrentContext(); // Color Declarations var darkBlue = UIColor.FromRGBA(0.053f, 0.123f, 0.198f, 1.000f); var lightBlue = UIColor.FromRGBA(0.191f, 0.619f, 0.845f, 1.000f); // Gradient Declarations var backgroundGradientColors = new CGColor [] { lightBlue.CGColor, darkBlue.CGColor }; var backgroundGradientLocations = new nfloat [] { 0.0f, 1.0f }; var backgroundGradient = new CGGradient(colorSpace, backgroundGradientColors, backgroundGradientLocations); // Rectangle Drawing var rectangleRect = new CGRect(rect.GetMinX() + (float)Math.Floor(rect.Width * -0.12917f + 0.5f), rect.GetMinY() + (float)Math.Floor(rect.Height * 0.00000f + 0.5f), (float)Math.Floor(rect.Width * 1.00000f + 0.5f) - (float)Math.Floor(rect.Width * -0.12917f + 0.5f), (float)Math.Floor(rect.Height * 1.00000f + 0.5f) - (float)Math.Floor(rect.Height * 0.00000f + 0.5f)); var rectanglePath = UIBezierPath.FromRect(rectangleRect); context.SaveState(); rectanglePath.AddClip(); context.DrawLinearGradient(backgroundGradient, new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMinY()), new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMaxY()), 0); context.RestoreState(); }
static AircraftTableViewCell() { DefaultPhoto = UIImage.FromResource(typeof(AircraftTableViewCell).Assembly, "FlightLog.Images.mini-plane72.png"); //NSString ns = new NSString ("MMMMMM"); //Console.WriteLine ("Width needed is: {0}", ns.DrawString (new RectangleF (0, 0, 200, 30), TailNumberFont).Width); //TailNumberWidth = ns.DrawString (new RectangleF (0, 0, 200, TailNumberSize), TailNumberFont).Width; using (var rgb = CGColorSpace.CreateDeviceRGB()) { float [] colorsBottom = { 1.00f, 1.00f, 1.00f, 0.5f, 0.93f, 0.93f, 0.93f, 0.5f }; BottomGradient = new CGGradient(rgb, colorsBottom, null); float [] colorsTop = { 0.93f, 0.93f, 0.93f, 0.5f, 1.00f, 1.00f, 1.00f, 0.5f }; TopGradient = new CGGradient(rgb, colorsTop, null); } }
public override void Draw(CGRect rect) { //Stopwatch s = new Stopwatch(); //s.Start(); //Console.WriteLine (" ----- SatBrightPickerView Draw"); CGContext context = UIGraphics.GetCurrentContext(); CGColor[] gradColors = new CGColor[] { UIColor.FromHSBA(hue, 1, 1, 1).CGColor, new CGColor(1, 1, 1, 1) }; nfloat[] gradLocations = new nfloat[] { 0.0f, 1.0f }; var colorSpace = CGColorSpace.CreateDeviceRGB(); CGGradient gradient = new CGGradient(colorSpace, gradColors, gradLocations); context.DrawLinearGradient(gradient, new CGPoint(rect.Size.Width, 0), new CGPoint(0, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation); gradColors = new CGColor[] { new CGColor(0, 0, 0, 0), new CGColor(0, 0, 0, 1) }; gradient = new CGGradient(colorSpace, gradColors, gradLocations); context.DrawLinearGradient(gradient, new CGPoint(0, 0), new CGPoint(0, rect.Size.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation); gradient.Dispose(); colorSpace.Dispose(); //s.Stop(); //Console.WriteLine("-----> SatBright Draw time: " + s.Elapsed.ToString()); } //draw
public override void Draw(CGRect rect) { //base.Draw(rect); GradientView formsGradientView = Element as GradientView; var currentContext = UIGraphics.GetCurrentContext(); currentContext.SaveState(); var colorSpace = CGColorSpace.CreateDeviceRGB(); var startColor = formsGradientView.StartColor; var startColorComponents = startColor.ToCGColor().Components; var middleColor = formsGradientView.MiddleColor; var middleColorComponents = middleColor.ToCGColor().Components; var endColor = formsGradientView.EndColor; var endColorComponents = endColor.ToCGColor().Components; nfloat[] colorComponents = { startColorComponents[0], startColorComponents[1], startColorComponents[2], startColorComponents[3], middleColorComponents[0], middleColorComponents[1], middleColorComponents[2], middleColorComponents[3], endColorComponents[0], endColorComponents[1], endColorComponents[2], endColorComponents[3] }; nfloat[] locations = { 0f, 0.5f, 1f }; var gradient = new CGGradient(colorSpace, colorComponents, locations); var startPoint = new CGPoint(0, NativeView.Bounds.Height); var endPoint = new CGPoint(NativeView.Bounds.Width, NativeView.Bounds.Height); currentContext.DrawLinearGradient(gradient, startPoint, endPoint, CGGradientDrawingOptions.None); currentContext.RestoreState(); }
public static void Draw(this LinearGradient 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 points = DetermineGradientPoints(target); var startPoint = new CGPoint(points[0] * bounds.Width, points[1] * bounds.Height); var endPoint = new CGPoint(points[2] * bounds.Width, points[3] * bounds.Height); var drawingFlags = GetGradientFlags(target); ctx.SaveState(); if (!target.Frame.IsEmpty) { ctx.ClipToRect(new CGRect(bounds.X + clippingBounds.X, bounds.Y + clippingBounds.Y, clippingBounds.Width, clippingBounds.Height)); } ctx.DrawLinearGradient(grad, startPoint, endPoint, drawingFlags); ctx.RestoreState(); grad.Dispose(); colorSpace.Dispose(); }
void Renderer_Element_SizeChanged(object sender, EventArgs e) { var element = sender as GradientView; if (element == null) return; var bounds = element.Bounds; var rect = new CGRect(bounds.X, bounds.Y, bounds.Width, bounds.Height); UIGraphics.BeginImageContext(rect.Size); using (CGContext g = UIGraphics.GetCurrentContext()) { using (var rgb = CGColorSpace.CreateDeviceRGB()) { nfloat[] colors = GetFloatArrayFromColors(element.StartColor, element.EndColor); var gradient = new CGGradient(rgb, colors, null); g.DrawRadialGradient(gradient, new CGPoint(0, 0), new nfloat(0), new CGPoint(100, 100), new nfloat(1000), CGGradientDrawingOptions.None); } using (var im = UIGraphics.GetImageFromCurrentImageContext()) using (var imageHolder = new UIImageView(im)) Container.AddSubview(imageHolder); UIGraphics.EndImageContext(); } }
public static void Draw(this EllipticalGradient 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.RotateCTM((nfloat)(target.Rotation * (Math.PI / 180))); ctx.ScaleCTM(scaleT.xx, scaleT.yy); ctx.DrawRadialGradient(grad, CGPoint.Empty, 0, CGPoint.Empty, gradRadius, drawingFlags); ctx.RestoreState(); grad.Dispose(); colorSpace.Dispose(); }
void RenderLinearGradient(CGContext graphics, CGRect pathBounds, LinearGradientBrush brush) { using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) { CGColor[] colors = new CGColor[brush.GradientStops.Count]; nfloat[] locations = new nfloat[brush.GradientStops.Count]; for (int index = 0; index < brush.GradientStops.Count; index++) { Color color = brush.GradientStops[index].Color; colors[index] = new CGColor(new nfloat(color.R), new nfloat(color.G), new nfloat(color.B), new nfloat(color.A)); locations[index] = new nfloat(brush.GradientStops[index].Offset); } CGGradient gradient = new CGGradient(rgb, colors, locations); if (brush.Transform != null) { CGAffineTransform transform = (CGAffineTransform)brush.Transform.GetNativeObject(); // TODO: This does not adequately work. // There is no real SpreadMethod in iOS. pathBounds = transform.TransformRect(pathBounds); } graphics.DrawLinearGradient(gradient, new CGPoint(pathBounds.Left + brush.StartPoint.X * pathBounds.Width, pathBounds.Top + brush.StartPoint.Y * pathBounds.Height), new CGPoint(pathBounds.Left + brush.EndPoint.X * pathBounds.Width, pathBounds.Top + brush.EndPoint.Y * pathBounds.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation); } }
void UpdateGradient() { if (_colors == null || _colors.Length < 2) { _gradient = null; return; } var colorspace = _colors [0].CGColor.ColorSpace; var gradientColors = new List <CGColor> (); foreach (var color in _colors) { gradientColors.Add(color.CGColor); } nfloat[] gradientLocations = null; if (Locations != null && Locations.Length == Colors.Length) { gradientLocations = Locations; } _gradient = new CGGradient(colorspace, gradientColors.ToArray(), gradientLocations); SetNeedsDisplay(); }
public override void Draw(CGRect rect) { using (CGContext context = UIGraphics.GetCurrentContext()) { switch (_Style) { case SIAlertViewBackgroundStyle.Gradient: { nfloat[] locations = { 0.0f, 1.0f }; nfloat[] colors = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f }; CGGradient gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), colors, locations); CGPoint center = new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height / 2); nfloat radius = (nfloat)Math.Min(Bounds.Size.Width, Bounds.Size.Height); context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation); break; } case SIAlertViewBackgroundStyle.Solid: { UIColor.FromWhiteAlpha(0f, 0.5f).SetColor(); context.SetFillColor(UIColor.FromWhiteAlpha(0f, 0.5f).CGColor); context.FillRect(Bounds); break; } } } }
private void DrawGradientInContext(CGRect rect) { //// General Declarations var colorSpace = CGColorSpace.CreateDeviceRGB(); var context = UIGraphics.GetCurrentContext(); //// Color Declarations var colorGradientEasyToHardColor = UIColor.FromRGBA(0.19f, 0.58f, 0.17f, 1.0f); var colorGradientEasyToHardColor2 = UIColor.FromRGBA(0.8f, 0.0f, 0.0f, 0.78f); //// Gradient Declarations var colorGradientEasyToHardColors = new CGColor [] { colorGradientEasyToHardColor.CGColor, UIColor.FromRGBA(0.5f, 0.3f, 0.09f, 0.9f).CGColor, colorGradientEasyToHardColor2.CGColor }; var colorGradientEasyToHardLocations = new nfloat [] { 0.0f, 0.67f, 1.0f }; var colorGradientEasyToHard = new CGGradient(colorSpace, colorGradientEasyToHardColors, colorGradientEasyToHardLocations); //// Rectangle Drawing var rectanglePath = UIBezierPath.FromRect(rect); context.SaveState(); rectanglePath.AddClip(); context.DrawLinearGradient(colorGradientEasyToHard, new CGPoint(0.0f, (rect.Width / 2)), new CGPoint(rect.Width, (rect.Width / 2)), 0); //context.DrawLinearGradient (colorGradientEasyToHard, new PointF (0.0f, 60.0f), new PointF (240.0f, 60.0f), 0); context.RestoreState(); //// Text Drawing CGRect textRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height); this.TextColor.SetFill(); textRect.Offset(0.0f, (textRect.Height - new NSString(this.Text).StringSize(this.Font, textRect.Size).Height) / 2.0f); new NSString(this.Text).DrawString(textRect, this.Font, UILineBreakMode.TailTruncation, UITextAlignment.Center); }
private void DrawGradient(CGRect rect, CGContext context) { //// General Declarations var colorSpace = CGColorSpace.CreateDeviceRGB(); //// Color Declarations var colorGradientEasyToHardColor = UIColor.FromRGBA(0.2f, 0.58f, 0.17f, 1.0f); var colorGradientEasyToHardColor2 = UIColor.FromRGBA(0.8f, 0.000f, 0.000f, 0.8f); //// Gradient Declarations var colorGradientEasyToHardColors = new CGColor [] { colorGradientEasyToHardColor.CGColor, UIColor.FromRGBA(0.5f, 0.3f, 0.09f, 0.9f).CGColor, colorGradientEasyToHardColor2.CGColor }; var colorGradientEasyToHardLocations = new nfloat [] { 0.0f, 0.67f, 1.0f }; var colorGradientEasyToHard = new CGGradient(colorSpace, colorGradientEasyToHardColors, colorGradientEasyToHardLocations); // Varied rect for different levels var varirect = new CGRect(rect.X, rect.Y, (float)(this._width * (rect.Width / 10)), rect.Height); //// White BackGround Drawing var bgWhitePath = UIBezierPath.FromRect(varirect); UIColor.White.SetFill(); bgWhitePath.Fill(); //// Rectangle Drawing var rectanglePath = UIBezierPath.FromRect(varirect); context.SaveState(); rectanglePath.AddClip(); context.DrawLinearGradient(colorGradientEasyToHard, new CGPoint(0.0f, (rect.Width / 2)), new CGPoint(rect.Width, (rect.Width / 2)), 0); context.RestoreState(); }
//Generated with PaintCode 2.2 public override void Draw(CGRect rect) { base.Draw(rect); // General Declarations var colorSpace = CGColorSpace.CreateDeviceRGB(); var context = UIGraphics.GetCurrentContext(); // Color Declarations var darkBlue = UIColor.FromRGBA(0.053f, 0.123f, 0.198f, 1.000f); var lightBlue = UIColor.FromRGBA(0.191f, 0.619f, 0.845f, 1.000f); // Gradient Declarations var backgroundGradientColors = new CGColor [] {lightBlue.CGColor, darkBlue.CGColor}; var backgroundGradientLocations = new nfloat [] {0.0f, 1.0f}; var backgroundGradient = new CGGradient(colorSpace, backgroundGradientColors, backgroundGradientLocations); // Rectangle Drawing var rectangleRect = new CGRect(rect.GetMinX() + (float)Math.Floor(rect.Width * -0.12917f + 0.5f), rect.GetMinY() + (float)Math.Floor(rect.Height * 0.00000f + 0.5f), (float)Math.Floor(rect.Width * 1.00000f + 0.5f) - (float)Math.Floor(rect.Width * -0.12917f + 0.5f), (float)Math.Floor(rect.Height * 1.00000f + 0.5f) - (float)Math.Floor(rect.Height * 0.00000f + 0.5f)); var rectanglePath = UIBezierPath.FromRect(rectangleRect); context.SaveState(); rectanglePath.AddClip(); context.DrawLinearGradient(backgroundGradient, new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMinY()), new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMaxY()), 0); context.RestoreState(); }
private void StartResizedImageRequest() { var sizeParamIndex = Url.IndexOf(MvxPlus.SizeParam, StringComparison.OrdinalIgnoreCase); var originalUrl = Url.Substring(0, sizeParamIndex); var sizeParamEndIndex = sizeParamIndex + MvxPlus.SizeParam.Length; var sizeParam = Url.Substring(sizeParamEndIndex, Url.Length - sizeParamEndIndex); var parameters = sizeParam.Split('>'); var size = new CGSize(float.Parse(parameters[0]), float.Parse(parameters[1])); var useClipMask = GetParamValue(parameters, MvxPlus.ClipParam) == "true"; var useGradient = GetParamValue(parameters, MvxPlus.GradientParam) == "true"; var imageCache = MvxPlus.SafeGetImageCache(); imageCache.RequestImage( originalUrl, image => RunAsyncWithLock(() => { var scaledSize = ResizeToFit(image.Size, size); UIGraphics.BeginImageContextWithOptions(size, !useClipMask, 1); // oval clip if (useClipMask) { var path = UIBezierPath.FromOval(new CGRect(CGPoint.Empty, size)); path.AddClip(); } image.Draw(new CGRect( new CGPoint( -((scaledSize.Width - size.Width) / 2), -((scaledSize.Height - size.Height) / 2)), scaledSize)); // gradient if (useGradient) { var colorspace = CGColorSpace.CreateDeviceRGB(); var gradient = new CGGradient(colorspace, new [] { ThemeColors.ContentDarkBackground.ColorWithAlpha(0.2f).CGColor, ThemeColors.ContentDarkBackground.ColorWithAlpha(0.8f).CGColor }, new nfloat[] { 0f, 1f }); UIGraphics.GetCurrentContext().DrawLinearGradient(gradient, CGPoint.Empty, new CGPoint(0, size.Height), CGGradientDrawingOptions.None); } var resizedImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); var stream = resizedImage.AsJPEG(0.86f).AsStream(); HandleSuccess(stream); }), FireDownloadFailed); }
public static UIImage BuildCoverFlow(UIImage image, float reflectionFraction) { int reflectionHeight = (int)(image.Size.Height * reflectionFraction); // gradient is always black and white and the mask must be in the gray colorspace var colorSpace = CGColorSpace.CreateDeviceGray(); // Create the bitmap context var gradientBitmapContext = new CGBitmapContext(IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None); // define the start and end grayscale values (with the alpha, even though // our bitmap context doesn't support alpha the gradien requires it) float [] colors = { 0, 1, 1, 1 }; // Create the CGGradient and then release the gray color space var grayScaleGradient = new CGGradient(colorSpace, colors, null); colorSpace.Dispose(); // create the start and end points for the gradient vector (straight down) var gradientStartPoint = new PointF(0, reflectionHeight); var gradientEndPoint = PointF.Empty; // draw the gradient into the gray bitmap context gradientBitmapContext.DrawLinearGradient(grayScaleGradient, gradientStartPoint, gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation); grayScaleGradient.Dispose(); // Add a black fill with 50% opactiy gradientBitmapContext.SetFillColor(0, 0.5f); gradientBitmapContext.FillRect(new RectangleF(0, 0, 1, reflectionHeight)); // conver the context into a CGImage and release the context var gradientImageMask = gradientBitmapContext.ToImage(); gradientBitmapContext.Dispose(); // create an image by masking the bitmap of the mainView content with the gradient view // then release the pre-masked content bitmap and the gradient bitmap var cgImage = image.CGImage; var reflectionImage = cgImage.WithMask(gradientImageMask); cgImage.Dispose(); gradientImageMask.Dispose(); var size = new SizeF(image.Size.Width, image.Size.Height + reflectionHeight); UIGraphics.BeginImageContext(size); image.Draw(PointF.Empty); var context = UIGraphics.GetCurrentContext(); context.DrawImage(new RectangleF(0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage); var result = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); reflectionImage.Dispose(); return(result); }
void FillPathWithGradient() { var gr = new CGGradient(CGColorSpace.CreateDeviceRGB(), _g.Colors.Select(c => c.GetCGColor()).ToArray(), _g.Locations.Select(g => (NativeValue)g).ToArray()); _c.SaveState(); _c.Clip(); _c.DrawLinearGradient(gr, _g.Start.ToPointF(), _g.End.ToPointF(), CGGradientDrawingOptions.DrawsAfterEndLocation | CGGradientDrawingOptions.DrawsBeforeStartLocation); _c.RestoreState(); }
public GradientTheme() { //BackgroundColor = UIColor.Clear; TextColor = UIColor.Black; TextShadowColor = UIColor.LightGray; TextShadowOffset = new SizeF(1, 0); gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1 }, new float[] { 0, 1 }); }
private void SetUp() { CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB (); gradient = new CGGradient ( colorSpace, new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1}, new float[] { 0, 1 }); }
public static UIImage AddImageReflection(UIImage image, float reflectionFraction) { int reflectionHeight = (int) (image.Size.Height * reflectionFraction); // Create a 2 bit CGImage containing a gradient that will be used for masking the // main view content to create the 'fade' of the reflection. The CGImageCreateWithMask // function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient // gradient is always black and white and the mask must be in the gray colorspace var colorSpace = CGColorSpace.CreateDeviceGray (); // Creat the bitmap context var gradientBitmapContext = new CGBitmapContext (IntPtr.Zero, 1, reflectionHeight, 8, 0, colorSpace, CGImageAlphaInfo.None); // define the start and end grayscale values (with the alpha, even though // our bitmap context doesn't support alpha the gradien requires it) float [] colors = { 0, 1, 1, 1 }; // Create the CGGradient and then release the gray color space var grayScaleGradient = new CGGradient (colorSpace, colors, null); colorSpace.Dispose (); // create the start and end points for the gradient vector (straight down) var gradientStartPoint = new PointF (0, reflectionHeight); var gradientEndPoint = PointF.Empty; // draw the gradient into the gray bitmap context gradientBitmapContext.DrawLinearGradient (grayScaleGradient, gradientStartPoint, gradientEndPoint, CGGradientDrawingOptions.DrawsAfterEndLocation); grayScaleGradient.Dispose (); // Add a black fill with 50% opactiy gradientBitmapContext.SetGrayFillColor (0, 0.5f); gradientBitmapContext.FillRect (new RectangleF (0, 0, 1, reflectionHeight)); // conver the context into a CGImage and release the context var gradientImageMask = gradientBitmapContext.ToImage (); gradientBitmapContext.Dispose (); // create an image by masking the bitmap of the mainView content with the gradient view // then release the pre-masked content bitmap and the gradient bitmap var reflectionImage = image.CGImage.WithMask (gradientImageMask); gradientImageMask.Dispose (); var size = new SizeF (image.Size.Width, image.Size.Height + reflectionHeight); UIGraphics.BeginImageContext (size); image.Draw (PointF.Empty); var context = UIGraphics.GetCurrentContext (); context.DrawImage (new RectangleF (0, image.Size.Height, image.Size.Width, reflectionHeight), reflectionImage); var result = UIGraphics.GetImageFromCurrentImageContext (); UIGraphics.EndImageContext (); reflectionImage.Dispose (); return result; }
static MessageSummaryView() { using (var colorspace = CGColorSpace.CreateDeviceRGB()) { Gradient = new CGGradient(colorspace, new[] { /* first */ .52f, .69f, .96f, 1, /* second */ .12f, .31f, .67f, 1 }, null); //new float [] { 0, 1 }); } }
public override void DrawInContext(CoreGraphics.CGContext ctx) { base.DrawInContext(ctx); var knobFrame = CGRect.Inflate(PaintFrame, -2.0f, -2.0f); UIBezierPath knobPath = UIBezierPath.FromRoundedRect((CGRect)knobFrame, (nfloat)knobFrame.Height * Slider.Curvaceousness / 2.0f); // 1) fill - with a subtle shadow ctx.SetShadow(new CGSize(0, 1), 1.0f, UIColor.Gray.CGColor); ctx.SetFillColor(Slider.KnobColor.CGColor); ctx.AddPath(knobPath.CGPath); ctx.FillPath(); // 2) outline ctx.SetStrokeColor(UIColor.Gray.CGColor); ctx.SetLineWidth((nfloat)0.5f); ctx.AddPath(knobPath.CGPath); ctx.StrokePath(); // 3) inner gradient var rect = CGRect.Inflate(knobFrame, -2.0f, -2.0f); var clipPath = UIBezierPath.FromRoundedRect((CGRect)rect, (nfloat)rect.Height * Slider.Curvaceousness / 2.0f); CGGradient myGradient; CGColorSpace myColorspace; nfloat[] locations = { 0.0f, 1.0f }; nfloat[] components = { 0.0f, 0.0f, 0.0f, 0.15f, // Start color 0.0f, 0.0f, 0.0f, 0.05f }; // End color myColorspace = CGColorSpace.CreateDeviceRGB(); // CGColorSpaceCreateDeviceRGB(); myGradient = new CGGradient(myColorspace, components, locations); CGPoint startPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMinY()); CGPoint endPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMaxY()); ctx.SaveState(); ctx.AddPath(clipPath.CGPath); ctx.Clip(); ctx.DrawLinearGradient((CGGradient)myGradient, (CGPoint)startPoint, (CGPoint)endPoint, (CGGradientDrawingOptions)0); myGradient.Dispose(); myColorspace.Dispose(); ctx.RestoreState(); // 4) highlight if (Highlighted) { // fill ctx.SetFillColor(UIColor.FromWhiteAlpha((nfloat)0.0f, (nfloat)0.1f).CGColor); ctx.AddPath(knobPath.CGPath); ctx.FillPath(); } }
public void Draw(GraphicsHandler graphics, bool stroke, FillMode fillMode, bool clip) { var outerRadius = Radius.Width; var yscale = Radius.Height / Radius.Width; var center = Center; var origin = GradientOrigin; var scale = 1f; var rect = graphics.Control.GetPathBoundingBox().ToEto(); if (stroke) { graphics.Control.ReplacePathWithStrokedPath(); } if (clip) { graphics.Clip(fillMode); } if (wrap != GradientWrapMode.Pad) { // use eto's transformrectangle as it'll make the rect encompass the resulting transformed area var boundRect = transform.Invert().ToEto().TransformRectangle(rect); // find max number of iterations we need to fill the bounding rectangle scale = GradientHelper.GetRadialScale(Center, Radius, GradientOrigin, boundRect); } if (Gradient == null || scale > lastScale) { var stops = GradientHelper.GetGradientStops(StartColor.ToCG(), EndColor.ToCG(), scale, wrap).ToList(); lastScale = scale; Gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), stops.Select(r => r.Item2).ToArray(), stops.Select(r => (nfloat)r.Item1).ToArray()); } else { scale = lastScale; } var scaledRect = new RectangleF(GradientOrigin - (GradientOrigin - Center + Radius) * scale, GradientOrigin + (Center + Radius - GradientOrigin) * scale); center = scaledRect.Center; outerRadius *= scale; // adjust center based on ellipse scale from gradient origin center.Y = origin.Y - (origin.Y - center.Y) / yscale; // scale to draw elliptical gradient var t = new CGAffineTransform(1, 0f, 0f, yscale, 0, origin.Y - origin.Y * yscale); t.Multiply(transform); graphics.Control.SaveState(); graphics.Control.ConcatCTM(t); graphics.Control.DrawRadialGradient(Gradient, origin.ToNS(), 0, center.ToNS(), outerRadius, CGGradientDrawingOptions.DrawsAfterEndLocation | CGGradientDrawingOptions.DrawsBeforeStartLocation); graphics.Control.RestoreState(); }
static HeaderView() { using (var rgb = CGColorSpace.CreateDeviceRGB()){ float [] colorsBottom = { 1, 1, 1, 1f, 0.97f, 0.97f, 0.97f, 1f }; Gradient = new CGGradient (rgb, colorsBottom, null); } }
public MovieElement(string caption) : base(UITableViewCellStyle.Default) { Caption = caption; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); gradient = new CGGradient( colorSpace, new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1}, new float[] { 0, 1 } ); }
public override void DrawInContext(CoreGraphics.CGContext ctx) { base.DrawInContext (ctx); var knobFrame = CGRect.Inflate(PaintFrame, -2.0f, -2.0f); UIBezierPath knobPath = UIBezierPath.FromRoundedRect((CGRect)knobFrame, (nfloat)knobFrame.Height * Slider.Curvaceousness / 2.0f); // 1) fill - with a subtle shadow ctx.SetShadow(new CGSize(0, 1), 1.0f, UIColor.Gray.CGColor); ctx.SetFillColor( Slider.KnobColor.CGColor); ctx.AddPath( knobPath.CGPath); ctx.FillPath (); // 2) outline ctx.SetStrokeColor(UIColor.Gray.CGColor); ctx.SetLineWidth((nfloat)0.5f); ctx.AddPath(knobPath.CGPath); ctx.StrokePath (); // 3) inner gradient var rect = CGRect.Inflate(knobFrame, -2.0f, -2.0f); var clipPath = UIBezierPath.FromRoundedRect ((CGRect)rect, (nfloat)rect.Height * Slider.Curvaceousness / 2.0f); CGGradient myGradient; CGColorSpace myColorspace; nfloat[] locations = { 0.0f, 1.0f }; nfloat[] components = { 0.0f, 0.0f, 0.0f , 0.15f, // Start color 0.0f, 0.0f, 0.0f, 0.05f }; // End color myColorspace = CGColorSpace.CreateDeviceRGB (); // CGColorSpaceCreateDeviceRGB(); myGradient = new CGGradient( myColorspace, components, locations); CGPoint startPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMinY()); CGPoint endPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMaxY()); ctx.SaveState (); ctx.AddPath( clipPath.CGPath); ctx.Clip (); ctx.DrawLinearGradient( (CGGradient)myGradient, (CGPoint)startPoint, (CGPoint)endPoint, (CGGradientDrawingOptions)0); myGradient.Dispose (); myColorspace.Dispose(); ctx.RestoreState(); // 4) highlight if (Highlighted) { // fill ctx.SetFillColor(UIColor.FromWhiteAlpha((nfloat)0.0f, (nfloat)0.1f).CGColor); ctx.AddPath( knobPath.CGPath); ctx.FillPath(); } }
public GradientDrawingView () : base () { using (var rgb = CGColorSpace.CreateDeviceRGB ()) { nfloat[] colors = { 204f / 255f, 224f / 255f, 244f / 255f, 10f, 29f / 255f, 156f / 255f, 215f / 255f, 10f, 0f / 255f, 50f / 255f, 126f / 255f, 10f, }; gradient = new CGGradient (rgb, colors, null); } }
public GradientTheme() { //BackgroundColor = UIColor.Clear; TextColor = UIColor.Black; TextShadowColor = UIColor.LightGray; TextShadowOffset = new SizeF(1, 0); gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1 }, new float[] { 0, 1 }); DrawElementViewAction = (rect, context, cell) => { DrawElementView(rect, context, cell); }; }
public void DrawContentView(RectangleF rect, CGContext context, UITableViewElementCell cell) { context.SaveState(); float r = 0; float g = 0; float b = 0; var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { r, g, b, 0.20f, r, g, b, 0.40f }, new float[] { 0, 1 }); context.DrawLinearGradient(gradient, new PointF(rect.Left, rect.Top), new PointF(rect.Left, rect.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation); context.RestoreState(); }
public SampleOwnerDrawnElement (string text, DateTime sent, string from) : base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement") { this.Subject = text; this.From = from; this.Sent = FormatDate(sent); CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); gradient = new CGGradient( colorSpace, new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1}, new float[] { 0, 1 } ); }
public override void Draw (RectangleF rect) { base.Draw (rect); // get graphics context CGContext gctx = UIGraphics.GetCurrentContext (); // set up drawing attributes gctx.SetLineWidth (4); UIColor.Yellow.SetStroke (); // stroke with a dashed line gctx.SetLineDash (3, new float[] {6,2}); // create geometry var path = new CGPath (); PointF origin = new PointF (Bounds.GetMidX (), Bounds.GetMinY () + 10); path.AddLines (new PointF[] { origin, new PointF (origin.X + 35, origin.Y + 80), new PointF (origin.X - 50, origin.Y + 30), new PointF (origin.X + 50, origin.Y + 30), new PointF (origin.X - 35, origin.Y + 80) }); path.CloseSubpath (); // add geometry to graphics context and draw it gctx.AddPath (path); gctx.DrawPath (CGPathDrawingMode.Stroke); // fill the star with a gradient gctx.AddPath (path); gctx.Clip (); RectangleF starBoundingBox = path.BoundingBox; float[] locations = { 0.0f, 1.0f }; float[] components = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }; using (var rgb = CGColorSpace.CreateDeviceRGB()) { CGGradient gradient = new CGGradient (rgb, components, locations); PointF gradientStart = new PointF (starBoundingBox.Left, starBoundingBox.Top); PointF gradientEnd = new PointF (starBoundingBox.Right, starBoundingBox.Bottom); gctx.DrawLinearGradient (gradient, gradientStart, gradientEnd, CGGradientDrawingOptions.DrawsBeforeStartLocation); } }
public override void Draw (CGRect rect) { base.Draw (rect); //get graphics context using (CGContext g = UIGraphics.GetCurrentContext ()) { //set up drawing attributes g.SetLineWidth (10); UIColor.Blue.SetFill (); UIColor.Red.SetStroke (); //create geometry var path = new CGPath (); path.AddLines (new CGPoint[]{ new CGPoint (100, 200), new CGPoint (160, 100), new CGPoint (220, 200)}); path.CloseSubpath (); //use a dashed line g.SetLineDash (0, new nfloat[]{10, 4}); //add geometry to graphics context and draw it g.AddPath (path); g.DrawPath (CGPathDrawingMode.FillStroke); // add the path back to the graphics context so that it is the current path g.AddPath (path); // set the current path to be the clipping path g.Clip (); // the color space determines how Core Graphics interprets color information using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) { CGGradient gradient = new CGGradient (rgb, new CGColor[] { UIColor.Blue.CGColor, UIColor.Yellow.CGColor }); // draw a linear gradient g.DrawLinearGradient ( gradient, new CGPoint (path.BoundingBox.Left, path.BoundingBox.Top), new CGPoint (path.BoundingBox.Right, path.BoundingBox.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation); } } }
public StoryDetailElement(AgileZenStory story) : base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement") { this.Text = story.Text; this.Status = story.Status; this.User = story.Owner.Name; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); gradient = new CGGradient( colorSpace, new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1}, new float[] { 0, 1 } ); }
public ProjectElement(AgileZenProject project) : base(UITableViewCellStyle.Default, "sampleOwnerDrawnElement") { this.Description = project.Description; this.Text = project.Name; this.CreatedTime = project.CreateTime; this.Id = project.Id; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); gradient = new CGGradient( colorSpace, new float[] { 0.95f, 0.95f, 0.95f, 1, 0.85f, 0.85f, 0.85f, 1}, new float[] { 0, 1 } ); }
static TableViewSectionView () { using (var rgb = CGColorSpace.CreateDeviceRGB()){ var colorsBottom = new nfloat[] { 1, 1, 1, 0f, 0.4f, 0.4f, 0.4f, .6f }; BottomGradient = new CoreGraphics.CGGradient (rgb, colorsBottom, null); var colorsTop = new nfloat[] { 0.8f, 0.8f, 0.8f, .4f, 1, 1, 1, 0f }; TopGradient = new CoreGraphics.CGGradient (rgb, colorsTop, null); } }
static CellBackgroundView() { using (var rgb = CGColorSpace.CreateDeviceRGB()){ float [] colorsBottom = { 1, 1, 1, .5f, 0.91f, 0.91f, 0.91f, .5f }; BottomGradient = new CGGradient (rgb, colorsBottom, null); float [] colorsTop = { 0.94f, 0.94f, 0.94f, .5f, 1, 1, 1, 0.5f }; TopGradient = new CGGradient (rgb, colorsTop, null); } }
public override void Draw(CGRect rect) { if (SplitViewController.DividerStyle == MGSplitViewDividerStyle.Thin) { base.Draw(rect); } else if (SplitViewController.DividerStyle == MGSplitViewDividerStyle.PaneSplitter) { // Draw gradient background. CGRect bounds = Bounds; CGColorSpace rgb = CGColorSpace.CreateDeviceRGB(); nfloat[] locations = {0, 1}; nfloat[] components = { 0.988f, 0.988f, 0.988f, 1.0f, // light 0.875f, 0.875f, 0.875f, 1.0f };// dark CGGradient gradient = new CGGradient(rgb, components, locations); CGContext context = UIGraphics.GetCurrentContext(); CGPoint start, end; if (SplitViewController.Vertical) { // Light left to dark right. start = new CGPoint(bounds.GetMinX(), bounds.GetMidY()); end = new CGPoint(bounds.GetMaxX(), bounds.GetMidY()); } else { // Light top to dark bottom. start = new CGPoint(bounds.GetMidX(), bounds.GetMinY()); end = new CGPoint(bounds.GetMidX(), bounds.GetMaxY()); } context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation); // Draw borders. float borderThickness = 10; UIColor.FromWhiteAlpha(0.7f, 1).SetColor(); CGRect borderRect = bounds; if (SplitViewController.Vertical) { borderRect.Width = borderThickness; context.FillRect(borderRect); borderRect.X = bounds.GetMaxX() - borderThickness; context.FillRect(borderRect); } else { borderRect.Height = borderThickness; context.FillRect(borderRect); borderRect.Y = bounds.GetMaxY() - borderThickness; context.FillRect(borderRect); } // Draw grip. DrawGripThumbInRect(bounds); } }
public static UIImage makeGradientProgressImage(int width, int height, float progress, float[] components, float[] locations) { //Create a CGBitmapContext object CGBitmapContext ctx = new CGBitmapContext(IntPtr.Zero, width, height, 8, 4 * width, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst); //Calculate the width of the rectangle based on the progress float percentWidth = width * progress; //Create a gradient object CGGradient gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), components, locations); //Draw a linear gradient to represent the progress bar ctx.DrawLinearGradient(gradient, new PointF(0, 0), new PointF(percentWidth, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation); //return a UIImage object return UIImage.FromImage(ctx.ToImage()); }
public override void DrawInContext (CoreGraphics.CGContext ctx) { CGRect rect = this.BoundsRect(); CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB (); nfloat [] colors = new nfloat[] { 0.42f, 0.66f, 0.31f, 1.0f, 0.95f, 0.76f, 0.20f, 1.0f, 0.80f, 0.25f, 0.15f, 1.0f }; CGGradient gradient = new CGGradient (colorSpace, colors, null); nuint tickSpaces = this.Axis.MajorTickCount - 1; nuint pointsCount = 5; if (this.Chart.Frame.Size.Height < this.Chart.Frame.Size.Width) { pointsCount = 3; } nfloat diameter = 8; nfloat spaceHeight = rect.Size.Height / tickSpaces; nfloat spacing = (spaceHeight - (pointsCount * diameter)) / (pointsCount + 1); nuint allPointsCount = pointsCount * tickSpaces; CGPath multipleCirclePath = new CGPath (); double y = rect.GetMinY() + diameter / 2.0f + spacing; for (uint i = 1; i <= allPointsCount; i++) { CGPoint center = new CGPoint (rect.GetMidX (), y); CGPath path = new CGPath (); path.AddArc (center.X, center.Y, (nfloat)diameter/2.0f, 0, (nfloat)Math.PI * 2, true); multipleCirclePath.AddPath (path); y += spacing + diameter; if (i % pointsCount == 0) { y += spacing; } } ctx.SaveState (); ctx.AddPath (multipleCirclePath); ctx.Clip (); CGPoint startPoint = new CGPoint (rect.GetMidX (), rect.GetMinY ()); CGPoint endPoint = new CGPoint (rect.GetMidX (), rect.GetMaxY()); ctx.DrawLinearGradient (gradient, startPoint, endPoint, 0); ctx.RestoreState (); base.DrawInContext (ctx); }
public override void Draw(CGRect rect) { base.Draw(rect); var context = UIGraphics.GetCurrentContext(); //context.BeginPath(); //context.ClipToRect(new RectangleF(63f, 0f, 3f, rect.Height)); using (var cs = CGColorSpace.CreateDeviceRGB ()) { using (var gradient = new CGGradient (cs, new nfloat[] { 1f, 1f, 1f, 1.0f, 0.7f, 0.7f, 0.7f, 1f, 1f, 1f, 1.0f, 1.0f }, new nfloat[] {0, 0.5f, 1f})) { context.DrawLinearGradient(gradient, new CGPoint(0, 0), new CGPoint(0, rect.Height), 0); } } }
public override void DrawInContext(CGContext ctx) { base.DrawInContext(ctx); var colorSpace = CGColorSpace.CreateDeviceRGB(); if (colorSpace == null) { throw new InvalidOperationException(); } var gradient = new CGGradient(colorSpace, new nfloat[] { 1f, 1f, 1f, 1f, 0.86f, 0.86f, 0.86f, 1f }, new nfloat[] { 0.2f, 0.95f }); var center = new CGPoint(this.Bounds.Width / 2, this.Bounds.Height / 2); var radius = new nfloat(Math.Min(this.Bounds.Width, this.Bounds.Height)); ctx.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation); }
public override void Draw(CGRect rect) { base.Draw(rect); var context = UIGraphics.GetCurrentContext(); var colorSpace = CGColorSpace.CreateDeviceRGB(); nfloat[] locations = { 0, 1 }; CGColor[] colors = { UIColor.FromRGB(0x8D, 0xCF, 0x16).CGColor, UIColor.FromRGB(0x65, 0xBD, 0x10).CGColor, }; var gradiend = new CGGradient(colorSpace, colors, locations); context.DrawLinearGradient(gradiend, new CGPoint(0, 0), new CGPoint(0, rect.Size.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation); gradiend.Dispose(); colorSpace.Dispose(); }
private UIImage GenerateBackgroundImage() { UIGraphics.BeginImageContextWithOptions(this.Bounds.Size, true, 1); // The location of the colors is at the start and end float[] locations = new float[] { 0.0f, 1.0f }; // These are the colors defined as RBGA values float[] components = new float[] { 0.18f, 0.53f, 0.78f, 1f, 0.11f, 0.34f, 0.5f, 1f }; var colorSpace = CGColorSpace.CreateDeviceRGB(); CGGradient gradient = new CGGradient(colorSpace, components, locations); UIGraphics.GetCurrentContext().DrawRadialGradient(gradient, Center, 0, Center, Bounds.Size.Width, CGGradientDrawingOptions.DrawsAfterEndLocation); return UIGraphics.GetImageFromCurrentImageContext(); }
public override void Draw(CGRect rect) { // Load image UIImage image = new UIImage("logo.png"); // Get drawing context CGContext ctx = UIGraphics.GetCurrentContext(); // get view bounds CGRect bounds = this.Bounds; // Find the center of view CGPoint center = new CGPoint(); center.X = bounds.X + bounds.Width / 2; center.Y = bounds.Y + bounds.Height / 2; // Compute the max radius of the circle float maxRadius = (float)Math.Sqrt(Math.Pow(bounds.Size.Width,2) + Math.Pow(bounds.Size.Height,2)) / 3.0f; ctx.SaveState(); // draw outline circle with 1 pt black shadow ctx.AddArc(center.X, center.Y, maxRadius, 0, (float)(Math.PI * 2), true); CGSize offset = new CGSize(0, 1); CGColor shadowColor = UIColor.Black.CGColor; ctx.SetShadow(offset, 2, shadowColor); ctx.DrawPath(CGPathDrawingMode.Stroke); // clear shadow ctx.RestoreState(); // set clipping circle ctx.AddArc(center.X, center.Y, maxRadius, 0, (float)(Math.PI * 2), true); ctx.Clip(); // Draw the image in the circle image.Draw(bounds); CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); nfloat[] components = new nfloat[8]{0.8f, 0.8f, 1, 1, 0.8f, 0.8f, 1, 0}; nfloat[] locations = new nfloat[2]{0.0f, 1}; CGGradient gradient = new CGGradient(colorSpace, components, locations); ctx.DrawLinearGradient(gradient, new CGPoint(bounds.Width / 2, 0), new CGPoint(bounds.Width / 2, bounds.Height / 2), 0); }
public void DrawElementView(RectangleF rect, CGContext context, UITableViewElementCell cell) { var gradientFrame = rect; var shineFrame = gradientFrame; shineFrame.Y += 1; shineFrame.X += 1; shineFrame.Width -= 2; shineFrame.Height = (shineFrame.Height / 2); CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); var gradient = new CGGradient( colorSpace, new float[] { 0f, 0f,0f, 0.70f, 0f, 0f, 0f, 0.40f}, new float[] { 0, 1 } ); var shineGradient = new CGGradient( colorSpace, new float[] { 1f, 1f, 1f, 0.80f, 1f, 1f, 1f, 0.10f}, new float[] { 0, 1 } ); if (Cell != null && Cell.Highlighted) { context.SetFillColorWithColor(HighlightColor.CGColor); } else { context.SetFillColorWithColor(CellBackgroundColor.CGColor); } context.FillRect(rect); context.DrawLinearGradient(gradient, new PointF(gradientFrame.Left, gradientFrame.Top), new PointF(gradientFrame.Left, gradientFrame.Bottom), CGGradientDrawingOptions.DrawsAfterEndLocation); context.DrawLinearGradient(shineGradient, new PointF(shineFrame.Left, shineFrame.Top), new PointF(shineFrame.Left, shineFrame.Bottom), CGGradientDrawingOptions.DrawsAfterEndLocation); }