protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            canvas.Clear(SKColors.White);

            var step = height / 4;

            using (var paint = new SKPaint())
                using (var effect = SKPathEffect.CreateDash(new[] { 15f, 5f }, 0))
                {
                    paint.IsStroke    = true;
                    paint.StrokeWidth = 4;
                    paint.PathEffect  = effect;
                    canvas.DrawLine(10, step, width - 10 - 10, step, paint);
                }

            using (var paint = new SKPaint())
                using (var effect = SKPathEffect.CreateDiscrete(10, 10))
                {
                    paint.IsStroke    = true;
                    paint.StrokeWidth = 4;
                    paint.PathEffect  = effect;
                    canvas.DrawLine(10, step * 2, width - 10 - 10, step * 2, paint);
                }

            using (var paint = new SKPaint())
                using (var dashEffect = SKPathEffect.CreateDash(new[] { 15f, 5f }, 0))
                    using (var discreteEffect = SKPathEffect.CreateDiscrete(10, 10))
                        using (var effect = SKPathEffect.CreateCompose(dashEffect, discreteEffect))
                        {
                            paint.IsStroke    = true;
                            paint.StrokeWidth = 4;
                            paint.PathEffect  = effect;
                            canvas.DrawLine(10, step * 3, width - 10 - 10, step * 3, paint);
                        }
        }
Ejemplo n.º 2
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            string text = "FUZZY";

            using (SKPaint textPaint = new SKPaint())
            {
                textPaint.Color      = SKColors.Purple;
                textPaint.PathEffect = SKPathEffect.CreateDiscrete(3f, 10f);

                // Adjust TextSize property so text is 95% of screen width
                float textWidth = textPaint.MeasureText(text);
                textPaint.TextSize *= 0.95f * info.Width / textWidth;

                // Find the text bounds
                SKRect textBounds;
                textPaint.MeasureText(text, ref textBounds);

                // Calculate offsets to center the text on the screen
                float xText = info.Width / 2 - textBounds.MidX;
                float yText = info.Height / 2 - textBounds.MidY;

                canvas.DrawText(text, xText, yText, textPaint);
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            float segLength = (float)segLengthSlider.Value;
            float deviation = (float)deviationSlider.Value;

            using (SKPaint paint = new SKPaint())
            {
                paint.Style       = SKPaintStyle.Stroke;
                paint.StrokeWidth = 5;
                paint.Color       = SKColors.Blue;

                using (SKPathEffect pathEffect = SKPathEffect.CreateDiscrete(segLength, deviation))
                {
                    paint.PathEffect = pathEffect;

                    SKRect rect = new SKRect(100, 100, info.Width - 100, info.Height - 100);
                    canvas.DrawRect(rect, paint);
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnPaintSurface(SKPaintGLSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);

            var canvas = e.Surface.Canvas;

            var size = Math.Min(e.RenderTarget.Width, e.RenderTarget.Height) - ProgressThickness;

            using (var paint = new SKPaint())
                using (var path = new SKPath()) {
                    var left   = (e.RenderTarget.Width - size) / 2f;
                    var top    = (e.RenderTarget.Height - size) / 2f;
                    var right  = left + size;
                    var bottom = top + size;

                    path.AddArc(new SKRect(left, top, right, bottom), StartingDegrees, EndingDegrees);

                    paint.IsAntialias = true;
                    paint.StrokeCap   = SKStrokeCap.Round;
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = ProgressColor.ToSKColor();
                    paint.StrokeWidth = ProgressThickness;

                    paint.PathEffect = SKPathEffect.CreateDiscrete(12f, 4f, (uint)Guid.NewGuid().GetHashCode());

                    canvas.Clear(Color.White.ToSKColor());
                    canvas.DrawPath(path, paint);
                }
        }
Ejemplo n.º 5
0
        void OnPaintShadedStar(object sender, SKPaintSurfaceEventArgs e)
        {
            int width  = e.Info.Width;
            int height = e.Info.Height;

            SKCanvas canvas = e.Surface.Canvas;

            using (SKPaint paint = new SKPaint())
            {
                canvas.Clear(Color.White.ToSKColor()); //paint it black

                paint.Color = Color.Green.ToSKColor();

                paint.PathEffect = SKPathEffect.CreateDiscrete(5.0f, 2.0f);

                paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0),
                                                             new SKPoint(256, 256),
                                                             new SKColor[] { Color.Lime.ToSKColor(), Color.Orange.ToSKColor() },
                                                             null, SKShaderTileMode.Clamp);

                paint.IsAntialias = true;

                canvas.DrawPath(GetStarPath(width / 2 - 128), paint);
            }
        }
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);

            var canvas = e.Surface.Canvas;

            var size = Math.Min(e.Info.Width, e.Info.Height) - ProgressThickness;

            canvas.Clear();

            using var paint = new SKPaint();

            paint.Style       = SKPaintStyle.Stroke;
            paint.StrokeCap   = SKStrokeCap.Round;
            paint.StrokeWidth = ProgressThickness;
            paint.IsAntialias = true;

            if (Jagged)
            {
                paint.PathEffect = SKPathEffect.CreateDiscrete(12f, 4f, (uint)Guid.NewGuid().GetHashCode());
            }

            using var path = new SKPath();

            var left   = (e.Info.Width - size) / 2f;
            var top    = (e.Info.Height - size) / 2f;
            var right  = left + size;
            var bottom = top + size;

            path.AddArc(new SKRect(left, top, right, bottom), 0, 360);

            paint.Color = ProgressColor.AddLuminosity(-.3d).ToSKColor();

            canvas.DrawPath(path, paint);

            path.Reset();

            path.AddArc(new SKRect(left, top, right, bottom), StartingDegrees, EndingDegrees);

            paint.Color = SKColors.Black;

            paint.ImageFilter = SKImageFilter.CreateBlur(3f, 3f);
            paint.BlendMode   = SKBlendMode.SrcATop;
            canvas.DrawPath(path, paint);

            paint.ImageFilter = null;
            paint.BlendMode   = SKBlendMode.SrcOver;
            paint.Color       = ProgressColor.ToSKColor();
            canvas.DrawPath(path, paint);
        }
Ejemplo n.º 7
0
    public void DrawSketch(SKCanvas canvas)
    {
        // Build OvalStyleFill Blur
        var OvalStyleFillBlur = SKImageFilter.CreateBlur(9.522291f, 4.249391f, null, null);

        // Fill color for Oval Style
        var OvalStyleFillColor = new SKColor(255, 0, 128, 255);

        // New Oval Style fill paint
        var OvalStyleFillPaint = new SKPaint()
        {
            Style       = SKPaintStyle.Fill,
            Color       = OvalStyleFillColor,
            BlendMode   = SKBlendMode.SrcOver,
            IsAntialias = true,
            PathEffect  = SKPathEffect.CreateDiscrete(11.70298f, 8.239141f),
            ImageFilter = OvalStyleFillBlur
        };

        // Frame color for Oval Style
        var OvalStyleFrameColor = new SKColor(204, 102, 255, 255);

        // New Oval Style frame paint
        var OvalStyleFramePaint = new SKPaint()
        {
            Style       = SKPaintStyle.Stroke,
            Color       = OvalStyleFrameColor,
            BlendMode   = SKBlendMode.SrcOver,
            IsAntialias = true,
            StrokeWidth = 1f,
            StrokeMiter = 4f,
            StrokeJoin  = SKStrokeJoin.Miter,
            StrokeCap   = SKStrokeCap.Butt
        };

        // Draw Oval shape
        canvas.DrawOval(new SKRect(51.79688f, 47.54688f, 235.5156f, 216.3242f), OvalStyleFillPaint);
        canvas.DrawOval(new SKRect(51.79688f, 47.54688f, 235.5156f, 216.3242f), OvalStyleFramePaint);
    }