コード例 #1
0
ファイル: QrScanPage.xaml.cs プロジェクト: kiva/Mikoba
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            float size = 600;
            float posX = (info.Width - size) / 2;
            float posY = (info.Height - size) / 2;

            using (SKPath path = new SKPath())
            {
                var fillRect  = SKRect.Create(info.Width, info.Height);
                var codeRect  = SKRect.Create(posX, posY, size, size);
                var roundRect = new SKRoundRect(codeRect, 20);
                canvas.ClipRoundRect(roundRect, SKClipOperation.Difference, true);

                SKColor maskColor;
                SKColor.TryParse("003AB6", out maskColor);

                using (SKPaint paint = new SKPaint())
                {
                    paint.Style = SKPaintStyle.Fill;
                    paint.Color = maskColor;
                    canvas.DrawRect(fillRect, paint);
                }
            }
        }
コード例 #2
0
        void OnColorSourceTapped(object sender, EventArgs e)
        {
            if (!(sender is BindableObject bindable) || !(bindable.BindingContext is ColorSource selectedColorSource))
            {
                return;
            }

            if (SelectedColorSource == selectedColorSource)
            {
                return;
            }

            selectedColorSource.IsSelected = true;

            if (SelectedColorSource != null)
            {
                SelectedColorSource.IsSelected = false;
            }

            SelectedColorSource = selectedColorSource;

            SKColor.TryParse(SelectedColorSource.Color.ToHex(), out SKColor sKColor);

            _color       = sKColor;
            _paint.Color = _color;
        }
コード例 #3
0
ファイル: GradientView.cs プロジェクト: DanielCauser/HOK
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            SKColor.TryParse(StartColor, out var stColor);
            SKColor.TryParse(EndColor, out var edColor);

            var     colors     = new SKColor[] { stColor, edColor };
            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);
        }
コード例 #4
0
            public static bool TryParse(string str, out SKColor color)
            {
                if (str.StartsWith("rgb(", StringComparison.Ordinal))
                {
                    str = str.Substring(4, str.Length - 4).TrimEnd(')');
                    var values = str.Split(',');
                    var r      = Convert.ToInt32(values[0]);
                    var g      = Convert.ToInt32(values[1]);
                    var b      = Convert.ToInt32(values[2]);
                    str = $"#{r:X2}{g:X2}{b:X2}";
                }

                if (!SKColor.TryParse(str, out color))
                {
                    string hexString = null;

                    if (HexValues.TryGetValue(str, out hexString))
                    {
                        return(SKColor.TryParse(hexString, out color));
                    }

                    return(false);
                }

                return(true);
            }
コード例 #5
0
        private void BackgroundGradient_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // get the brush based on the theme
            SKColor gradientStart;

            SKColor.TryParse("#373B44", out gradientStart);
            SKColor gradientMid;

            SKColor.TryParse("#355C7D", out gradientMid);
            SKColor gradientEnd;

            SKColor.TryParse("#4286f4", out gradientEnd);

            // gradient background with 3 colors
            SKPaint backgroundBrush = new SKPaint();

            backgroundBrush.Shader = SKShader.CreateRadialGradient(
                new SKPoint(0, info.Height * .8f),
                info.Height * .8f,
                new SKColor[] { gradientStart, gradientMid, gradientEnd },
                new float[] { 0, .5f, 1 },
                SKShaderTileMode.Clamp);

            SKRect backgroundBounds = new SKRect(0, 0, info.Width, info.Height);

            canvas.DrawRect(backgroundBounds, backgroundBrush);
        }
コード例 #6
0
ファイル: SSShapeGenerator.cs プロジェクト: firots/SSCreator
        private void drawRectangle(SSShape rectangle, SKCanvas canvas)
        {
            using (var paint = new SKPaint()) {
                paint.IsAntialias = true;

                SKRect rect = new SKRect();
                rect.Size = new SKSize(rectangle.size.width, rectangle.size.height);
                var position = PositionHelper.getPosition(rectangle.alignX, rectangle.alignY, rect.Width, rect.Height, canvasSize);
                rect.Location = new SKPoint(position.x, position.y);

                if (rectangle.fillStyle == FillStyle.Solid)
                {
                    SKColor.TryParse(rectangle.fillColor, out SKColor color);
                    color       = color.WithAlpha(rectangle.alpha);
                    paint.Color = color;
                }
                else if (rectangle.fillStyle == FillStyle.Gradient)
                {
                    var startPoint = GradientHelper.getRectPoint(rect, (SSGradientDirection)rectangle.gradient?.startPoint);
                    var endPoint   = GradientHelper.getRectPoint(rect, (SSGradientDirection)rectangle.gradient?.endPoint);
                    paint.Shader = GradientHelper.createGradient((SSGradient)rectangle.gradient, startPoint, endPoint);
                }
                canvas.DrawRect(rect, paint);
            }
        }
コード例 #7
0
        async Task InitChart()
        {
            Acr.UserDialogs.UserDialogs.Instance.ShowLoading();

            await Task.Delay(700);

            List <Microcharts.Entry> entries = new List <Microcharts.Entry>();

            Color color = (Color)Application.Current.Resources["brandBlue"];

            //SKColor barColor = SKColor.FromHsl((float)color.Hue / 255, (float)color.Saturation / 255, (float)color.Luminosity / 255, (byte)color.A);
            SKColor barColor;

            SKColor.TryParse(color.GetHexString(), out barColor);

            ViewModel = ViewModel ?? new UsageViewModel();

            foreach (var usage in ViewModel.GasUsage)
            {
                entries.Add(new Microcharts.Entry(usage.Value)
                {
                    Color = barColor, Label = usage.Date.ToString("MMMM").Substring(0, 1), ValueLabel = usage.Value.ToString()
                });
            }

            var chart = new BarChart()
            {
                Entries = entries
            };


            this.usageChart.Chart = chart;

            Acr.UserDialogs.UserDialogs.Instance.HideLoading();
        }
コード例 #8
0
        public static bool TryParse(string str, out SKColor color)
        {
            if (str == "transparent")
            {
                color = SKColor.Empty;
                return(true);
            }

            if (str.StartsWith("rgb(", StringComparison.Ordinal))
            {
                str = str.Substring(4, str.Length - 4).TrimEnd(')');
                var values = str.Split(',');
                var r      = int.Parse(values[0]);
                var g      = int.Parse(values[1]);
                var b      = int.Parse(values[2]);
                str = $"#{r:X2}{g:X2}{b:X2}";
            }

            if (!SKColor.TryParse(str, out color))
            {
                if (HexValues.TryGetValue(str, out var hexString))
                {
                    return(SKColor.TryParse(hexString, out color));
                }

                return(false);
            }

            return(true);
        }
コード例 #9
0
        public virtual Chart Build()
        {
            var labels = Labels;
            var values = Values;
            var colors = Colors;

            if (Labels.Count != Values.Count)
            {
                throw new Exception($"{nameof(labels)} and {nameof(values)} have different length.");
            }

            var entries = Enumerable.Range(0, labels.Count).Select(i =>
            {
                var color = SKColor.Empty;

                if (colors == null || colors.Count <= 0 || !SKColor.TryParse(colors[i], out color))
                {
                    color = DefinedColors[i % DefinedColors.Length];
                }

                return(new Entry(values[i])
                {
                    Label = labels[i],
                    Color = color,
                    ValueLabel = values[i].ToString()
                });
            });

            var chart = new TChart();

            chart.Entries = entries;
            return(chart);
        }
コード例 #10
0
        /// <summary>
        /// Draws grid lines to match boundaries for 10 character PlusCodes.
        /// </summary>
        /// <param name="totalArea">the GeoArea to draw lines in</param>
        /// <returns>the byte array for the maptile png file</returns>
        public byte[] DrawCell10GridLines(GeoArea totalArea)
        {
            int      imageSizeX = IMapTiles.SlippyTileSizeSquare;
            int      imageSizeY = IMapTiles.SlippyTileSizeSquare;
            SKBitmap bitmap     = new SKBitmap(imageSizeX, imageSizeY, SKColorType.Rgba8888, SKAlphaType.Premul);
            SKCanvas canvas     = new SKCanvas(bitmap);
            var      bgColor    = new SKColor();

            SKColor.TryParse("00000000", out bgColor);
            canvas.Clear(bgColor);
            canvas.Scale(1, -1, imageSizeX / 2, imageSizeY / 2);
            SKPaint paint = new SKPaint();
            SKColor color = new SKColor();

            SKColor.TryParse("#00CCFF", out color);
            paint.Color       = color;
            paint.Style       = SKPaintStyle.Stroke;
            paint.StrokeWidth = 1;
            paint.IsAntialias = true;

            double degreesPerPixelX = totalArea.LongitudeWidth / imageSizeX;
            double degreesPerPixelY = totalArea.LatitudeHeight / imageSizeY;

            //This is hardcoded to Cell 8 spaced gridlines.
            var imageLeft            = totalArea.WestLongitude;
            var spaceToFirstLineLeft = (imageLeft % resolutionCell10);

            var imageBottom            = totalArea.SouthLatitude;
            var spaceToFirstLineBottom = (imageBottom % resolutionCell10);

            double lonLineTrackerDegrees = imageLeft - spaceToFirstLineLeft;            //This is degree coords

            while (lonLineTrackerDegrees <= totalArea.EastLongitude + resolutionCell10) //This means we should always draw at least 2 lines, even if they're off-canvas.
            {
                var geoLine = new LineString(new Coordinate[] { new Coordinate(lonLineTrackerDegrees, 90), new Coordinate(lonLineTrackerDegrees, -90) });
                var points  = PolygonToSKPoints(geoLine, totalArea, degreesPerPixelX, degreesPerPixelY);
                canvas.DrawLine(points[0], points[1], paint);
                lonLineTrackerDegrees += resolutionCell10;
            }

            double latLineTrackerDegrees = imageBottom - spaceToFirstLineBottom;        //This is degree coords

            while (latLineTrackerDegrees <= totalArea.NorthLatitude + resolutionCell10) //This means we should always draw at least 2 lines, even if they're off-canvas.
            {
                var geoLine = new LineString(new Coordinate[] { new Coordinate(180, latLineTrackerDegrees), new Coordinate(-180, latLineTrackerDegrees) });
                var points  = PolygonToSKPoints(geoLine, totalArea, degreesPerPixelX, degreesPerPixelY);
                canvas.DrawLine(points[0], points[1], paint);
                latLineTrackerDegrees += resolutionCell10;
            }

            var ms   = new MemoryStream();
            var skms = new SkiaSharp.SKManagedWStream(ms);

            bitmap.Encode(skms, SkiaSharp.SKEncodedImageFormat.Png, 100);
            var results = ms.ToArray();

            skms.Dispose(); ms.Close(); ms.Dispose();
            return(results);
        }
コード例 #11
0
        public static SKColor GetSKColor(string hexCode)
        {
            SKColor _color = SKColors.Transparent;

            SKColor.TryParse(hexCode, out _color);

            return(_color);
        }
コード例 #12
0
        private SKColor FromString(string color)
        {
            SKColor skcolor = SKColors.Empty;

            SKColor.TryParse(color, out skcolor);

            return(skcolor);
        }
コード例 #13
0
 /// <summary>
 /// Parses the provided colour name into an SKColor.
 /// </summary>
 /// <param name="colour">The string to parse.</param>
 private SKColor GetColour(string hex)
 {
     if (!SKColor.TryParse(hex, out SKColor colour))
     {
         return(SKColors.Red);
     }
     return(colour);
 }
コード例 #14
0
        /// <inheritdoc />
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrWhiteSpace((string)value))
            {
                return(SKColor.Empty);
            }

            return(SKColor.TryParse((string)value, out SKColor color) ? color : SKColor.Empty);
        }
コード例 #15
0
        internal static SKBitmap WatermarkText(SKBitmap original, ResizeParams resizeParams, WatermarkTextModel watermarkText)
        {
            var toBitmap = new SKBitmap(original.Width, original.Height);
            var canvas   = new SKCanvas(toBitmap);
            // Draw a bitmap rescaled


            var paint = new SKPaint();

            //paint.Typeface = SKTypeface.FromFamilyName("Arial");
            paint.TextSize  = watermarkText.TextSize;
            paint.TextAlign = watermarkText.TextAlign.GetSKTextAlign();
            if (watermarkText.IsVerticalText)
            {
                paint.IsVerticalText = true;
            }
            else
            {
                paint.IsLinearText = true;
            }

            if (watermarkText.Type == 2)
            {
                paint.IsStroke    = true;
                paint.StrokeWidth = watermarkText.StrokeWidth;
                paint.StrokeCap   = SKStrokeCap.Round;
            }
            paint.Style         = watermarkText.Type.GetSKPaintStyle();
            paint.FilterQuality = watermarkText.Quality.GetSKFilterQuality();
            paint.TextSkewX     = watermarkText.TextSkewX;
            paint.IsAntialias   = true;

            //https://www.color-hex.com/
            if (SKColor.TryParse(watermarkText.Color, out SKColor color))
            {
                paint.Color = color;
            }
            else
            {
                paint.Color = SKColors.Black;
            }

            canvas.DrawBitmap(original, 0, 0);

            var x = watermarkText.PositionMeasureType == 1 ? watermarkText.X : watermarkText.X.ToPixel(original.Width);
            var y = watermarkText.PositionMeasureType == 1 ? watermarkText.Y : watermarkText.Y.ToPixel(original.Height);

            canvas.DrawText(watermarkText.Value, x, y, paint);

            canvas.Flush();

            canvas.Dispose();
            paint.Dispose();
            original.Dispose();

            return(toBitmap);
        }
コード例 #16
0
 private static SKColor[] getColors(string[] colors)
 {
     SKColor[] skColors = new SKColor[colors.Length];
     for (int i = 0; i < colors.Length; i++)
     {
         SKColor.TryParse(colors[i], out SKColor color);
         skColors[i] = color;
     }
     return(skColors);
 }
コード例 #17
0
 private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e)
 {
     if (!(BindingContext is ClockViewModel clockViewModel))
     {
         return;
     }
     if (SKColor.TryParse(ColorsAndHex[clockViewModel.CurrentProfile.HandsColor], out SKColor handsColor) &&
         SKColor.TryParse(ColorsAndHex[clockViewModel.CurrentProfile.FaceColor], out SKColor faceColor))
     {
         SKCanvas canvas = e.Surface.Canvas;
         clockViewModel.ClockDrawerService.DrawClock(canvas, handsColor,
                                                     faceColor, clockViewModel.GetTime(), e.Info.Height, e.Info.Width);
     }
 }
コード例 #18
0
ファイル: SSTextGenerator.cs プロジェクト: firots/SSCreator
 private SSPosition drawLabel(SSLabel label, SKCanvas canvas, SSPosition position)
 {
     using (SKPaint paint = new SKPaint()) {
         paint.TextSize    = label.fontSize;
         paint.IsAntialias = true;
         paint.Typeface    = getFont(label);
         SKColor.TryParse(label.color, out SKColor color);
         color       = color.WithAlpha(label.alpha);
         paint.Color = color;
         float height = label.fontSize;
         canvas.DrawText(label.text, position.x, position.y, paint);
         position.x += paint.MeasureText(label.text);
         return(position);
     }
 }
コード例 #19
0
        private void OnDataReceived(object sender, DataReceivedEventArgs e)
        {
            var data = e.Get <RedrawData>();

            currentText = data.Text;

            if (SKColor.TryParse(data.Color, out var color))
            {
                currentColor = color;
            }

            currentSize = data.Size;

            skiaView.Invalidate();
        }
コード例 #20
0
        public static bool TryParse(string input, out SKColor result)
        {
            result = default;

            if (string.IsNullOrWhiteSpace(input))
            {
                return(false);
            }
            else if (namedColors.ContainsKey(input))
            {
                result = namedColors[input];
                return(true);
            }

            return(SKColor.TryParse(input, out result));
        }
コード例 #21
0
        private IEnumerable <SKColor> MatchColor(string name)
        {
            if (WCUtils.ColorNames.Contains(name))
            {
                yield return(WCUtils.ColorLibrary[name]);

                yield break;
            }

            if (string.Equals(name, "transparent", StringComparison.OrdinalIgnoreCase))
            {
                yield return(SKColor.Empty);

                yield break;
            }

            if (WildcardPattern.ContainsWildcardCharacters(name))
            {
                bool foundMatch = false;
                var  pattern    = new WildcardPattern(name, WildcardOptions.IgnoreCase);
                foreach (var color in WCUtils.ColorLibrary)
                {
                    if (pattern.IsMatch(color.Key))
                    {
                        yield return(color.Value);

                        foundMatch = true;
                    }
                }

                if (foundMatch)
                {
                    yield break;
                }
            }

            if (SKColor.TryParse(name, out SKColor c))
            {
                yield return(c);

                yield break;
            }

            throw new ArgumentTransformationMetadataException();
        }
コード例 #22
0
        private async Task <bool> PlaceMultipixelPacket(string instructions, short placeDiscordUserId)
        {
            PlaceDBManager placeDBManager = PlaceDBManager.Instance();

            foreach (var instruction in instructions.Split(';'))
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();

                var delay = Task.Delay(990); // wait for 990 ms instead of 1000ms so if the main method takes longer we dont loose too many
                var args  = instruction.Split('|');

                short x = short.Parse(args[0]);
                short y = short.Parse(args[1]);

                //SKColor color = ColorTranslator.FromHtml(args[2]);

                if (!SKColor.TryParse(args[2], out SKColor color))
                {
                    continue;
                }

                var success = placeDBManager.PlacePixel(x, y, color, placeDiscordUserId);

                watch.Stop();

                // TODO ensure the perf info is updated if only multipixels are placed, for now this should be fine

                if (success)
                {
                    PlaceModule.PixelPlacementTimeLastMinute.Add(watch.ElapsedMilliseconds);
                }
                else
                {
                    lock (PlaceModule.PlaceAggregateObj)
                    {
                        PlaceModule.FailedPixelPlacements++;
                    }
                }

                await delay;
            }

            return(true);
        }
コード例 #23
0
 private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e)
 {
     if (BindingContext is ClockViewModel clockViewModel)
     {
         if (currentData.CurrentProfile == null)
         {
             return;
         }
         bool     handsParsed = SKColor.TryParse(colorsRepository.ColorAndHex[currentData.CurrentProfile.HandsColor], out SKColor handsColor);
         bool     faceParsed  = SKColor.TryParse(colorsRepository.ColorAndHex[currentData.CurrentProfile.FaceColor], out SKColor faceColor);
         DateTime?time        = clockViewModel.GetTimeByTimezone();
         if (handsParsed && faceParsed && time != null)
         {
             SKCanvas canvas = e.Surface.Canvas;
             clockViewModel.DrawClock(handsColor, faceColor, canvas, (DateTime)time, e.Info.Height, e.Info.Width);
         }
     }
 }
コード例 #24
0
ファイル: Attributes.cs プロジェクト: swipswaps/PSWordCloud
        private SKColor[] MatchColor(string name)
        {
            string errorMessage;

            if (WCUtils.ColorNames.Contains(name))
            {
                return(new[] { WCUtils.ColorLibrary[name] });
            }

            if (string.Equals(name, "transparent", StringComparison.OrdinalIgnoreCase))
            {
                return(new[] { SKColor.Empty });
            }

            if (WildcardPattern.ContainsWildcardCharacters(name))
            {
                var pattern = new WildcardPattern(name, WildcardOptions.IgnoreCase);

                var colorList = new List <SKColor>();
                foreach (var color in WCUtils.ColorLibrary)
                {
                    if (pattern.IsMatch(color.Key))
                    {
                        colorList.Add(color.Value);
                    }
                }

                if (colorList.Count > 0)
                {
                    return(colorList.ToArray());
                }

                errorMessage = $"Wildcard pattern '{name}' did not match any known color names.";
                throw new ArgumentTransformationMetadataException(errorMessage);
            }

            if (SKColor.TryParse(name, out SKColor c))
            {
                return(new[] { c });
            }

            errorMessage = $"Unrecognised color name: '{name}'.";
            throw new ArgumentTransformationMetadataException(errorMessage);
        }
コード例 #25
0
        public static SKColor?ParseColorString(string tint)
        {
            if (string.IsNullOrEmpty(tint))
            {
                return(null);
            }

            if (SKColor.TryParse(tint, out var color))
            {
                return(color);
            }

            if (ColorTable.TryGetNamedColor(tint, out color))
            {
                return(color);
            }

            return(null);
        }
コード例 #26
0
ファイル: MainWindow.xaml.cs プロジェクト: tyty999/Svg.Skia
        private void ItemExport_Click(object sender, RoutedEventArgs e)
        {
            if (items.SelectedIndex >= 0 && items.Items.GetItemAt(items.SelectedIndex) is Item item)
            {
                var dlg = new Microsoft.Win32.SaveFileDialog()
                {
                    Filter = "Png Files (*.png)|*.png;" +
                             "|Jpg Files (*.jpg)|*.jpg;" +
                             "|Jpeg Files (*.jpeg)|*.jpeg;" +
                             "|Webp Files (*.webp)|*.webp;" +
                             "|Pdf Files (*.pdf)|*.pdf;" +
                             "|Xps Files (*.xps)|*.xps;" +
                             "|Svg Files (*.svg)|*.svg;" +
                             "|All Files (*.*)|*.*",
                    FileName    = item.Name,
                    DefaultExt  = "png",
                    FilterIndex = 0
                };
                if (dlg.ShowDialog() == true && dlg.FileName != null)
                {
                    var textBackground = TextOutputBackground.Text;
                    var textScaleX     = TextOutputScaleX.Text;
                    var textScaleY     = TextOutputScaleY.Text;

                    if (SKColor.TryParse(textBackground, out var skBackgroundColor) == false)
                    {
                        return;
                    }

                    if (float.TryParse(textScaleX, out var scaleX) == false)
                    {
                        return;
                    }

                    if (float.TryParse(textScaleY, out var scaleY) == false)
                    {
                        return;
                    }

                    VM.ExportItem(item.SvgPath, dlg.FileName, skBackgroundColor, scaleX, scaleY);
                }
            }
        }
コード例 #27
0
        public void InvalidHexToColor()
        {
            var tuples = new List <string> {
                "#ABCDE",
                "#123456ug",
                "12sd",
                "11111111111111",
            };

            foreach (var item in tuples)
            {
                // values
                string hex = item;

                SKColor color;
                var     result = SKColor.TryParse(hex, out color);

                Assert.IsFalse(result, hex);
            }
        }
コード例 #28
0
        public IActionResult Rectangle(int width, int height, string bgColor, string fgColor, string text = null, int?textSize = null)
        {
            if (width * height > _options.MaxSize)
            {
                return(UnprocessableEntity());
            }

            if (width <= 0 || height <= 0 ||
                !SKColor.TryParse(bgColor ?? _options.BackgroundColor, out var skBgColor) ||
                !SKColor.TryParse(fgColor ?? _options.ForegroundColor, out var skFgColor))
            {
                return(BadRequest());
            }

            var image = Draw.Steps(
                Draw.BackgroundColor(skBgColor),
                Draw.CenteredText(text ?? $"{width}×{height}", textSize ?? _options.TextSize, skFgColor));

            return(new ImageResult(width, height, image));
        }
コード例 #29
0
        public void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();
            using (SKPaint paint = new SKPaint())
            {
                SKColor SpideyBlueBckGrnd;
                SKColor.TryParse("#020f1f", out SpideyBlueBckGrnd);
                SKColor SpideyLightBlueBckGrnd;
                SKColor.TryParse("#001c41", out SpideyLightBlueBckGrnd);
                paint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(info.Rect.Top, info.Rect.Top),
                    new SKPoint(info.Rect.Bottom, info.Rect.Bottom),
                    new SKColor[] { SpideyBlueBckGrnd, SpideyLightBlueBckGrnd },
                    new float[] { 0, 0.60f },
                    SKShaderTileMode.Mirror);
                canvas.DrawRect(info.Rect, paint);
            }
        }
コード例 #30
0
        private SortedDictionary <float, SKColor> ReadStops(XElement e)
        {
            var stops = new SortedDictionary <float, SKColor>();

            var ns = e.Name.Namespace;

            foreach (var se in e.Elements(ns + "stop"))
            {
                var style = ReadStyle(se);

                var  offset = ReadNumber(style["offset"]);
                var  color  = SKColors.Black;
                byte alpha  = 255;

                string stopColor;
                if (style.TryGetValue("stop-color", out stopColor))
                {
                    // preserve alpha
                    if (SKColor.TryParse(stopColor, out color) && color.Alpha == 255)
                    {
                        alpha = color.Alpha;
                    }
                }

                string stopOpacity;
                if (style.TryGetValue("stop-opacity", out stopOpacity))
                {
                    alpha = (byte)(ReadNumber(stopOpacity) * 255);
                }

                color         = color.WithAlpha(alpha);
                stops[offset] = color;
            }

            return(stops);
        }