Exemplo n.º 1
0
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            canvas.DrawColor(SKColors.White);

            using (var paint = new SKPaint())
                using (var filter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 5.0f))
                {
                    paint.IsAntialias = true;
                    paint.TextSize    = 120;
                    paint.TextAlign   = SKTextAlign.Center;
                    paint.MaskFilter  = filter;

                    canvas.DrawText("SkiaSharp", width / 2f, height / 2f, paint);
                }
        }
Exemplo n.º 2
0
        public static void DrawReflectText(string TEXT, SKBitmap info, SKCanvas canvas)
        {
            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                // Set text color to blue
                paint.Color = SKColors.Blue;

                // Set text size to fill 90% of width
                paint.TextSize = 100;
                float width = paint.MeasureText(TEXT);
                float scale = 0.9f * info.Width / width;
                paint.TextSize *= scale;

                // Get text bounds
                SKRect textBounds = new SKRect();
                paint.MeasureText(TEXT, ref textBounds);

                // Calculate offsets to position text above center
                float xText = info.Width / 2 - textBounds.MidX;
                float yText = info.Height / 2;

                // Draw unreflected text
                canvas.DrawText(TEXT, xText, yText, paint);

                // Shift textBounds to match displayed text
                textBounds.Offset(xText, yText);

                // Use those offsets to create a gradient for the reflected text
                paint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(0, textBounds.Top),
                    new SKPoint(0, textBounds.Bottom),
                    new SKColor[] { paint.Color.WithAlpha(0),
                                    paint.Color.WithAlpha(0x80) },
                    null,
                    SKShaderTileMode.Clamp);

                // Create a blur mask filter
                paint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, paint.TextSize / 36);

                // Scale the canvas to flip upside-down around the vertical center
                canvas.Scale(1, -1, 0, yText);

                // Draw reflected text
                canvas.DrawText(TEXT, xText, yText, paint);
            }
        }
Exemplo n.º 3
0
        public void setBlurOfPaint(SKPaint paint)
        {
            if (this.radius <= 0)
            {
                return;
            }

            if (this.blurMaskFilter == null)
            {
                this.blurMaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, SKMaskFilter.ConvertRadiusToSigma(this.radius)); // 1.7f - manually to make it look like paintcode
            }
            //this.blurMaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, this.radius/5);

            paint.MaskFilter = this.blurMaskFilter;
            //paint.Color = this.color; // sure?
        }
        public void TestExtractAlpha()
        {
            var path   = Path.Combine(PathToImages, "color-wheel.png");
            var bitmap = SKBitmap.Decode(path);

            var alpha = new SKBitmap();

            SKPointI offset;
            SKPaint  paint = new SKPaint {
                MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 5.0f)
            };

            Assert.True(bitmap.ExtractAlpha(alpha, paint, out offset));

            Assert.AreEqual(new SKPointI(-7, -7), offset);
        }
Exemplo n.º 5
0
        public SKPaint CreateTextPaint(SeriesValue seriesValue, SKColor color)
        {
            var textPaint = new SKPaint
            {
                Color    = color,
                TextSize = chart.TextSize
            };

            if (!seriesValue.Focused && chart.HasShapeFocused)
            {
                SKBlurStyle blurStyle = SKBlurStyle.Normal;
                textPaint.MaskFilter = SKMaskFilter.CreateBlur(blurStyle, chart.Sigma);
            }

            return(textPaint);
        }
Exemplo n.º 6
0
        public SKPaint CreateSlicePaint(SeriesValue seriesValue)
        {
            var paint = new SKPaint
            {
                StrokeWidth = 30,
                Style       = SKPaintStyle.Fill,
                Color       = seriesValue.HasColour() ? seriesValue.Colour : palette.GetAvaibleColour(),
            };

            if (!seriesValue.Focused && chart.HasShapeFocused)
            {
                SKBlurStyle blurStyle = SKBlurStyle.Normal;
                paint.MaskFilter = SKMaskFilter.CreateBlur(blurStyle, chart.Sigma);
            }

            return(paint);
        }
Exemplo n.º 7
0
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            canvas.DrawColor(SKColors.White);

            SKPoint3 direction = new SKPoint3(1.0f, 1.0f, 1.0f);

            using (var paint = new SKPaint())
                using (var filter = SKMaskFilter.CreateEmboss(2.0f, direction, 0.3f, 0.1f))
                {
                    paint.IsAntialias = true;
                    paint.TextSize    = 120;
                    paint.TextAlign   = SKTextAlign.Center;
                    paint.MaskFilter  = filter;

                    canvas.DrawText("SkiaSharp", width / 2f, height / 2f, paint);
                }
        }
Exemplo n.º 8
0
        public SKPaint CreateDotPaint(SeriesValue value)
        {
            var paint = new SKPaint
            {
                Color       = !value.Colour.Equals(SKColor.Empty) ? value.Colour : palette.GetAvaibleColour(),
                StrokeWidth = 20,
                TextSize    = chart.TextSize,
                TextAlign   = SKTextAlign.Center
            };

            if (!value.Focused && chart.HasShapeFocused)
            {
                SKBlurStyle blurStyle = SKBlurStyle.Normal;
                paint.MaskFilter = SKMaskFilter.CreateBlur(blurStyle, chart.Sigma);
            }

            return(paint);
        }
        public void DesenharSvg(ISvgElement svgDoc, Transformacao matriz)
        {
            using (var paint = new SKPaint())
            {
                var escala  = matriz.Escala.Value;
                var posicao = matriz.Posicao.Value;
                var matrix  = SKMatrix.CreateScaleTranslation(escala.X, escala.Y, posicao.X, posicao.Y);

                paint.IsAntialias = true;
                paint.ImageFilter = Color.FromHex("#66000000").ToSKDropShadow(6, 12f);
                paint.MaskFilter  = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, Constantes.SVG.Mapa.DESFOQUE_SOMBRA);

                if (svgDoc is SKSvgElement svgElement)
                {
                    _canvas.DrawPicture(svgElement.ToSkia(), ref matrix, paint);
                }
            }
        }
Exemplo n.º 10
0
        private void DrawInnerBlurRectangle(SKCanvas canvas, SKRect rect)
        {
            // create the rounded rectangle
            var roundedRect = new SKPath();

            roundedRect.AddRoundRect(rect, 10, 10);

            // draw the white background
            var p = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.White
            };

            canvas.DrawPath(roundedRect, p);

            using (new SKAutoCanvasRestore(canvas))
            {
                // clip the canvas to stop the blur from appearing outside
                canvas.ClipPath(roundedRect, SKClipOperation.Intersect, true);

                // draw the wide blur all around
                p.Color       = SKColors.Black;
                p.Style       = SKPaintStyle.Stroke;
                p.StrokeWidth = 2;
                p.MaskFilter  = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 2);
                canvas.Translate(0.5f, 1.5f);
                canvas.DrawPath(roundedRect, p);

                // draw the narrow blur at the top
                p.StrokeWidth = 1;
                p.MaskFilter  = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 1);
                canvas.DrawPath(roundedRect, p);
            }

            // draw the border
            p.StrokeWidth = 2;
            p.MaskFilter  = null;
            p.Color       = SampleMedia.Colors.XamarinGreen;
            canvas.DrawPath(roundedRect, p);
        }
Exemplo n.º 11
0
        public static void DrawBlurText(string TEXT, SKBitmap info, SKCanvas canvas, SKBlurStyle blurStyle, float sigma)
        {
            canvas.Clear(SKColors.Pink);

            using (SKPaint paint = new SKPaint())
            {
                // Set SKPaint properties
                paint.TextSize   = (info.Width - 100) / (TEXT.Length / 2);
                paint.MaskFilter = SKMaskFilter.CreateBlur(blurStyle, sigma);

                // Get text bounds and calculate display rectangle
                SKRect textBounds = new SKRect();
                paint.MeasureText(TEXT, ref textBounds);
                SKRect textRect = new SKRect(0, 0, info.Width, textBounds.Height + 50);

                // Center the text in the display rectangle
                float xText = textRect.Width / 2 - textBounds.MidX;
                float yText = textRect.Height / 2 - textBounds.MidY;

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

            canvas.Clear(SKColors.Pink);

            // Get values from XAML controls
            SKBlurStyle blurStyle =
                (SKBlurStyle)(blurStylePicker.SelectedIndex == -1 ?
                              0 : blurStylePicker.SelectedItem);

            float sigma = (float)sigmaSlider.Value;

            using (SKPaint paint = new SKPaint())
            {
                // Set SKPaint properties
                paint.TextSize   = (info.Width - 100) / (TEXT.Length / 2);
                paint.MaskFilter = SKMaskFilter.CreateBlur(blurStyle, sigma);

                // Get text bounds and calculate display rectangle
                SKRect textBounds = new SKRect();
                paint.MeasureText(TEXT, ref textBounds);
                SKRect textRect = new SKRect(0, 0, info.Width, textBounds.Height + 50);

                // Center the text in the display rectangle
                float xText = textRect.Width / 2 - textBounds.MidX;
                float yText = textRect.Height / 2 - textBounds.MidY;

                canvas.DrawText(TEXT, xText, yText, paint);

                // Calculate rectangle for bitmap
                SKRect bitmapRect = new SKRect(0, textRect.Bottom, info.Width, info.Height);
                bitmapRect.Inflate(-50, -50);

                canvas.DrawBitmap(bitmap, bitmapRect, BitmapStretch.Uniform, paint: paint);
            }
        }
Exemplo n.º 13
0
        void DrawChoice(SKCanvas canvas)
        {
            if (GameControls is null)
            {
                return;
            }
            if (GameControls.ViewModel.ChosenTurn != -1)
            {
                int     numDash    = 5;
                float   dashLength = 2 * (numDash - 1) + numDash;
                float[] dashArray  =
                {
                    ViewModel.CellSize / dashLength,
                    2 * ViewModel.CellSize / dashLength
                };
                SKPaint paint = new SKPaint
                {
                    Color       = SKColors.White,
                    Style       = SKPaintStyle.StrokeAndFill,
                    PathEffect  = SKPathEffect.CreateDash(dashArray, 20),
                    StrokeWidth = 8,
                    MaskFilter  = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 1)
                };
                SKPoint cur = ViewModel.GameTrajectory.Last();

                var(dir1, dir2) = GameControls.ViewModel.CurrentDirections;

                canvas.DrawLine(
                    ViewModel.GetGridPoint(cur),
                    ViewModel.GetGridPoint(ViewModel.MovePoint(cur, dir1)),
                    paint
                    );
                canvas.DrawLine(
                    ViewModel.GetGridPoint(cur),
                    ViewModel.GetGridPoint(ViewModel.MovePoint(cur, dir2)),
                    paint
                    );
            }
        }
Exemplo n.º 14
0
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            canvas.DrawColor(SKColors.White);

            using (var paint = new SKPaint())
                using (var filter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 5.0f))
                {
                    paint.IsAntialias = true;
                    paint.TextSize    = 120;
                    paint.TextAlign   = SKTextAlign.Center;
                    paint.MaskFilter  = filter;

                    canvas.DrawText("SkiaSharp", width / 2f, height / 4f, paint);
                }

            // scale up so we don't have to change the values in the method
            var scaling = 3;

            canvas.Scale(scaling, scaling);
            var rect = SKRect.Create(width / (3f * scaling), height / (2f * scaling), width / (3f * scaling), height / (4f * scaling));

            DrawInnerBlurRectangle(canvas, rect);
        }
        static void DrawBox(SKCanvas canvas, float startLeft, float startTop, float scaledBoxWidth, float scaledBoxHeight, SKColor color)
        {
            var strokePaint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 5,
                PathEffect  = SKPathEffect.CreateDash(new[] { 20f, 20f }, 20f)
            };

            DrawBox(canvas, strokePaint, startLeft, startTop, scaledBoxWidth, scaledBoxHeight);

            var blurStrokePaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 5,
                PathEffect  = SKPathEffect.CreateDash(new[] { 20f, 20f }, 20f),
                IsAntialias = true,
                MaskFilter  = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 0.57735f * radius + 0.5f)
            };

            DrawBox(canvas, blurStrokePaint, startLeft, startTop, scaledBoxWidth, scaledBoxHeight);
        }
Exemplo n.º 16
0
        private static void DrawCallout(CalloutStyle callout, SKCanvas canvas, SKPath path)
        {
            using var shadow = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Stroke, StrokeWidth = 1.5f, Color = SKColors.Gray, MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, callout.ShadowWidth) };
            using var fill   = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Fill, Color = callout.BackgroundColor.ToSkia() };
            using var stroke = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Stroke, Color = callout.Color.ToSkia(), StrokeWidth = callout.StrokeWidth };

            canvas.DrawPath(path, shadow);
            canvas.DrawPath(path, fill);
            canvas.DrawPath(path, stroke);
        }
Exemplo n.º 17
0
        private void CanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKSurface surface = e.Surface;
            SKCanvas  canvas  = surface.Canvas;

            canvas.Clear();
            canvas.Translate(12, 12);
            _width  = e.Info.Width - 24;
            _height = e.Info.Height - 24;
            _dip    = e.Info.Height / (float)CanvasView.Height / 2.5f;

            _circleRadius = _height / 2f;
            float circlePosY = _height / 2f;

            if (_shouldRedrawCircle)
            {
                _shouldRedrawCircle = false;
                _circlePath         = new SKPathDraggable {
                    IsDraggableY = false
                };
                float circleOffset = _circleRadius + 5 * _dip;
                _circlePath.AddCircle(circleOffset, circleOffset, _circleRadius);

                _lightStroke.StrokeWidth    = 2 * _dip;
                _shadowBlurPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 5 * _dip);
                _shadowBlurOuter.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Outer, 10 * _dip);
                _circleSurface = SKSurface.Create(_height + 10, _height + 10, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
                SKCanvas cirCanv = _circleSurface.Canvas;
                cirCanv.Clear();
                cirCanv.DrawCircle(circleOffset - _circleRadius * 0.16f, circleOffset, _circleRadius - _circleRadius * 0.16f,
                                   _shadowBlurPaint);
                cirCanv.DrawPath(_circlePath, _lightColorPaint);

                _colorPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 3 * _dip);
                cirCanv.DrawOval(circleOffset - _circleRadius * 0.24f, circleOffset, _circleRadius - _circleRadius * 0.26f,
                                 _circleRadius - _circleRadius * 0.14f, _colorPaint);

                _colorPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 8 * _dip);
                cirCanv.DrawOval(circleOffset - _dip, circleOffset, _circleRadius * 0.8f, _circleRadius * 0.9f, _colorPaint);

                _colorPaint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 12 * _dip);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius * 0.5f, _colorPaint);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius + _dip, _lightStroke);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius * 0.75f - _dip, _shadowBlurOuter);
                cirCanv.DrawCircle(circleOffset, circleOffset, _circleRadius * 0.75f, _lightStroke);

                _colorPaint.MaskFilter = null;

                _sliderBox = new SKRect(0, 7 * _dip, _width, _height - 7 * _dip);
            }

            _circlePath.OffsetX = 3 * _dip + (_width - 2 * _circleRadius - 3 * _dip) * TotalProgress;
            _circlePath.UpdatePosition();
            float circlePosX = _circlePath.TightBounds.MidX;

            float  hardShadowXOffset = 6 * _dip;
            float  hardShadowYOffset = 8 * _dip;
            SKPath path = new SKPath();

            path.AddCircle(circlePosX - 5 * _dip, circlePosY, _circleRadius);
            path.AddRect(_sliderBox);

            path.Offset(new SKPoint(hardShadowXOffset, hardShadowYOffset));
            canvas.DrawPath(path, _shadowHardPaint);

            canvas.DrawRect(_sliderBox, _lightColorPaint);

            float todayPos = 5 * _dip + (_width - _circleRadius) * TodayGoal;

            canvas.DrawRect(new SKRect(todayPos, 7 * _dip, todayPos + 6 * _dip, _height - 7 * _dip), _gray);
            _sliderBox.Right = circlePosX;
            canvas.DrawRect(_sliderBox, _colorPaint);
            _sliderBox.Right = _width;

            canvas.DrawSurface(_circleSurface, circlePosX - _circleRadius - 10 * _dip, -5 * _dip);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Create callout outline in background
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void HandlePaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            canvas.Scale(_mapControl.SkiaScale, _mapControl.SkiaScale);

            var shadow = new SKPaint {
                IsAntialias = true, Style = SKPaintStyle.Stroke, StrokeWidth = 1.5f, Color = SKColors.Gray, MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, _shadowWidth)
            };
            var fill = new SKPaint {
                IsAntialias = true, Style = SKPaintStyle.Fill, Color = BackgroundColor.ToSKColor()
            };
            var stroke = new SKPaint {
                IsAntialias = true, Style = SKPaintStyle.Stroke, Color = Color.ToSKColor(), StrokeWidth = StrokeWidth
            };

            if (_path == null)
            {
                UpdatePath();
            }

            canvas.Clear(SKColors.Transparent);
            canvas.DrawPath(_path, shadow);
            canvas.DrawPath(_path, fill);
            canvas.DrawPath(_path, stroke);

            // Draw close button
            if (IsCloseVisible)
            {
                var paint = new SKPaint {
                    IsAntialias = true, Style = SKPaintStyle.Stroke, Color = SKColors.DarkGray, StrokeWidth = 2
                };
                var pos = _close.Bounds.Offset(_grid.Bounds.Left, _grid.Bounds.Top).Inflate(-4, -4);
                canvas.DrawLine((float)pos.Left, (float)pos.Top, (float)pos.Right, (float)pos.Bottom, paint);
                canvas.DrawLine((float)pos.Left, (float)pos.Bottom, (float)pos.Right, (float)pos.Top, paint);
            }
        }