protected override void OnPaintSurface(SKPaintSurfaceEventArgs e) { base.OnPaintSurface(e); SKImageInfo info = e.Info; SKSurface surface = e.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); if (StartColor != Color.Transparent || EndColor != Color.Transparent) { var colors = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() }; SKPoint startPoint = new SKPoint(0, 0); SKPoint endPoint = Horizontal ? new SKPoint(info.Width, 0) : new SKPoint(0, info.Height); var shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp); SKPaint paint = new SKPaint { Style = SKPaintStyle.Fill, Shader = shader }; canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), paint); } }
protected override SKShader CreateGradientShader(SKImageInfo info) { return(SKShader.CreateLinearGradient( new SKPoint(0, info.Height / 2), new SKPoint(info.Width / 2, info.Height / 2), new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() }, new float[] { 0, 0.5f }, SKShaderTileMode.Mirror)); }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); var colors = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor()}; SKPoint startPoint = new SKPoint(0,0); SKPoint endPoint = Horizontal ? new SKPoint(info.Width, 0) : new SKPoint(0, info.Height); var shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp); SKPaint paint = new SKPaint { Style = SKPaintStyle.Fill, Shader = shader }; canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), paint); }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); var colors = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() }; using (SKPaint paint = new SKPaint()) { // Createrectangle SKRect rect = new SKRect(0, 0, info.Width, info.Height); paint.Shader = SKShader.CreateLinearGradient( new SKPoint(rect.Left, rect.Top), new SKPoint(rect.Right, rect.Bottom), colors, null, SKShaderTileMode.Clamp); // Draw the gradient on the rectangle canvas.DrawRect(rect, paint); } // Create linear gradient from upper-left to lower-right /*SKPoint startPoint = new SKPoint(0, 0); * SKPoint endPoint = Horizontal ? new SKPoint(info.Width, 0) : new SKPoint(0, info.Height); * * var shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp); * * SKPaint paint = new SKPaint * { * Style = SKPaintStyle.Fill, * Shader = shader * }; * * canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), paint);*/ }
/// <summary> /// Create the gradient color for the border path /// If only start or end color is set no gradient will be used. /// </summary> private void CreateShader() { if (!GradientColor) { _paint.Color = StartColor.ToSKColor(); } else { _paint.Shader = SKShader.CreateLinearGradient( start: new SKPoint(0, 0), end: new SKPoint(SkCanvasView.CanvasSize.Width, SkCanvasView.CanvasSize.Height), colors: new SKColor[] { ((Color)StartColor).ToSKColor(), ((Color)EndColor).ToSKColor() }, colorPos: new float[] { 0, 1 }, mode: SKShaderTileMode.Clamp); } }
private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { try { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); var startPoint = new SKPoint(0, 0); var endPoint = new SKPoint(info.Width, info.Height); SKColor[] colors; SKShader shader; if (HasGradientStartInset) { colors = new SKColor[] { StartColor.ToSKColor(), StartColor.ToSKColor(), EndColor.ToSKColor() }; shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, new float[] { 0, GradientStartInsetPercent, 1 }, SKShaderTileMode.Clamp); } else { colors = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() }; shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp); } var mainPaint = new SKPaint { Style = SKPaintStyle.Fill, Shader = shader }; canvas.DrawRect(new SKRect(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y), mainPaint); } catch (Exception ex) { // Don't crash for a pretty effect System.Diagnostics.Debug.WriteLine(ex); } }
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e) { base.OnPaintSurface(e); var canvas = e.Surface.Canvas; canvas.Clear(); int width = e.Info.Width; int height = e.Info.Height; SKPaint backPaint = new SKPaint { Style = SKPaintStyle.Fill, Color = SKColors.WhiteSmoke, }; canvas.DrawRect(new SKRect(0, 0, width, height), backPaint); canvas.Save(); canvas.Translate(width / 2, height / 2); canvas.Scale(Math.Min(width / 210f, height / 520f)); var rect = new SKRect(-100, -100, 100, 100); // Add a buffer for the rectangle rect.Inflate(-10, -10); var bgColorPaint = new SKPaint { Color = BGColor.ToSKColor(), IsAntialias = true, Style = SKPaintStyle.Fill, StrokeWidth = 0 }; var barColorPaint = new SKPaint { Color = BarColor.ToSKColor(), IsAntialias = true, Style = SKPaintStyle.Fill, StrokeWidth = 0 }; var frameColorPaint = new SKPaint { Color = FrameColor.ToSKColor(), IsAntialias = true, Style = SKPaintStyle.Stroke, StrokeWidth = 2 }; var skrect = new SKRect(0, 0, PGWidth, PGHeight); var skRoundRect = new SKRoundRect(skrect, PGHeight / 2, PGHeight / 2); canvas.DrawRoundRect(0, 0, PGWidth, PGHeight, PGHeight / 2, PGHeight / 2, bgColorPaint); canvas.DrawRoundRect(skRoundRect, frameColorPaint); canvas.ClipRoundRect(skRoundRect, SKClipOperation.Intersect); if (StartColor != Color.Default && EndColor != Color.Default) { barColorPaint.Shader = SKShader.CreateLinearGradient( new SKPoint(skrect.Left, skrect.Bottom), new SKPoint(skrect.Right, skrect.Top), new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() }, new float[] { 0, 1 }, SKShaderTileMode.Repeat); } canvas.DrawRoundRect(0, 0, PGWidth * Progress / 100, PGHeight, PGWidth / 2, 0, barColorPaint); canvas.Restore(); }