public override Hair Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var colorConverter = (JsonConverter <SKColor>)options.GetConverter(typeof(SKColor)); switch (reader.TokenType) { case JsonTokenType.None: case JsonTokenType.PropertyName: if (!reader.Read()) { throw new JsonException("expected token to parse"); } break; } SKColor?dark = null, @base = null, highlight = null; var startingDepth = reader.CurrentDepth; do { if (!reader.Read()) { throw new JsonException("expected token to parse"); } switch (reader.TokenType) { case JsonTokenType.PropertyName when reader.ValueTextEquals("dark"): dark = colorConverter.Read(ref reader, typeof(SKColor), options); break; case JsonTokenType.PropertyName when reader.ValueTextEquals("base"): @base = colorConverter.Read(ref reader, typeof(SKColor), options); break; case JsonTokenType.PropertyName when reader.ValueTextEquals("highlight"): highlight = colorConverter.Read(ref reader, typeof(SKColor), options); break; } }while (reader.CurrentDepth > startingDepth); if (!dark.HasValue) { ThrowIncompleteObject(nameof(dark)); } if ([email protected]) { ThrowIncompleteObject(nameof(@base)); } if (!highlight.HasValue) { ThrowIncompleteObject(nameof(highlight)); } return(new Hair(dark.Value, @base.Value, highlight.Value)); }
/// <summary> /// Plot data from arrays of matched X/Y points /// </summary> public void Scatter( double[] xs, double[] ys, string label = null, SKColor?color = null, bool secondY = false ) { var style = new Style( label: label, color: color, plotNumber: plottables.Count, secondY: secondY ); var scatterPlot = new Plottables.Scatter(xs, ys, style); plottables.Add(scatterPlot); if (style.secondY) { axes2.y.display = true; } AutoAxis(); }
/// <summary> /// Set text and style for the vertical axis label /// </summary> public void YLabel( string text = null, float?fontSize = null, string fontName = null, SKColor?color = null, bool secondY = false ) { var lbl = (secondY) ? y2Label : yLabel; var tck = (secondY) ? y2Ticks : yTicks; lbl.text = text; if (fontSize != null) { lbl.fontSize = (float)fontSize; } if (fontName != null) { lbl.fontName = fontName; } if (color != null) { lbl.fontColor = (SKColor)color; if (secondY) { y2Ticks.yTickColor = (SKColor)color; } else { yTicks.yTickColor = (SKColor)color; } } }
public void YTicks( SKColor?color = null, bool secondY = false ) { var ax = (secondY) ? axes2.y : axes.y; //if (color!=null) }
/// <summary> /// Class constructor. /// </summary> public Surface(SKCanvas canvas, double width, double height, SKColor?color = null) { _width = width; _height = height; _canvas = canvas; _bitmap = null; _canvas.Clear(color ?? Colors.Transparent); }
/// <summary> /// Class constructor. /// </summary> public Surface(double width, double height, SKColor?color = null) { _width = width; _height = height; _bitmap = new SKBitmap((int)Math.Round(_width * RenderProps.DisplayScale), (int)Math.Round(_height * RenderProps.DisplayScale)); _canvas = new SKCanvas(_bitmap); _canvas.Clear(color ?? (!GameConfig.Instance.Debug ? Colors.Transparent : Colors.DebugBlack1)); }
public static IEnumerable <SKTextRun> Create(string text, SKTextRunLookup lookup) { var runs = new List <SKTextRun>(); if (string.IsNullOrEmpty(text)) { return(runs); } var start = 0; while (start < text.Length) { var startIndex = text.IndexOf(IconTemplateBegin, start, StringComparison.Ordinal); if (startIndex == -1) { break; } var endIndex = text.IndexOf(IconTemplateEnd, startIndex, StringComparison.Ordinal); if (endIndex == -1) { break; } var pre = text.Substring(start, startIndex - start); var post = text.Substring(endIndex + IconTemplateEnd.Length); var expression = text.Substring(startIndex + IconTemplateBegin.Length, endIndex - startIndex - IconTemplateEnd.Length); var segments = expression.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); expression = segments.FirstOrDefault(); SKColor?color = null; foreach (var item in segments) { var pair = item.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); switch (pair[0].ToLower()) { case "color": if (pair.Length > 1 && !string.IsNullOrWhiteSpace(pair[1])) { color = SKColor.Parse(pair[1]); } break; } } if (!string.IsNullOrEmpty(pre)) { runs.Add(new SKTextRun(pre)); } if (lookup.TryLookup(expression, out var typeface, out var character)) { runs.Add(new SKTextRun(character) { Typeface = typeface, Color = color }); }
public byte[] PreviewiOSIcon(byte[] image, float?imageScale = null, SKColor?imageMaskColor = null, SKColor?backgroundColor = null, float?cornerRadius = null, SKSizeI?size = null) { var result = MobileiOSIconService.Preview(image, imageScale, imageMaskColor, backgroundColor, cornerRadius, size); return(result); }
public byte[] GetWindowsIco(byte[] image, float?imageScale = null, SKColor?imageMaskColor = null, SKColor?backgroundColor = null, float?cornerRadius = null, List <SKSizeI> resolutions = null) { var result = WindowsIcoService.FromData(image, imageScale, imageMaskColor, backgroundColor, cornerRadius, resolutions); return(result); }
public TextLine(string text = "", double size = 24, SKColor?color = null, double topMargin = 0, double bottomMargin = 0, Alignment alignment = Alignment.Left) { Text = text; Size = size; Color = color != null ? (SKColor)color : Colors.White; TopMargin = topMargin; BottomMargin = bottomMargin; Alignment = alignment; }
private static SKBitmap LoadSvgBitmap(string svgPath, SKColor?background = null) { // open the SVG var svg = new SKSvg(); svg.Load(svgPath); return(CreateBitmap(svg, background)); }
public Dictionary <string, byte[]> GetiOSIcon(byte[] image, float?imageScale = null, SKColor?imageMaskColor = null, SKColor?backgroundColor = null, float?cornerRadius = null) { backgroundColor = backgroundColor ?? SKColors.White; var result = MobileiOSIconService.FromData(image, imageScale, imageMaskColor, backgroundColor, cornerRadius); return(result); }
public void SetupDisplay(int width, int height, SKColor?clear_color = null) { this.Bitmap = (this.Bitmap == null) ? new SKBitmap(width, height) : this.Bitmap.Resize(new SKSizeI(width, height), SKFilterQuality.High); this.Canvas = new SKCanvas(this.Bitmap); if (clear_color.HasValue) { this.Canvas.Clear(clear_color.Value); } }
/// <summary> /// Defines a column in a table. /// </summary> /// <param name="ColumnId">Column ID</param> /// <param name="Header">Optional localized header.</param> /// <param name="DataSourceId">Optional Data Suorce ID reference.</param> /// <param name="Partition">Optional partition reference.</param> /// <param name="FgColor">Optional Foreground Color.</param> /// <param name="BgColor">Optional Background Color.</param> /// <param name="Alignment">Optional Column Alignment.</param> /// <param name="NrDecimals">Optional Number of Decimals.</param> public Column(string ColumnId, string Header, string DataSourceId, string Partition, SKColor?FgColor, SKColor?BgColor, ColumnAlignment?Alignment, byte?NrDecimals) { this.columnId = ColumnId; this.header = Header; this.dataSourceId = DataSourceId; this.partition = Partition; this.fgColor = FgColor; this.bgColor = BgColor; this.alignment = Alignment; this.nrDecimals = NrDecimals; }
public Style(int colorIndex = 0, SKColor?color = null, float lineWidth = 1, float markerSize = 3, string fontName = "Segoe UI", float fontSize = 12, string label = null) { this.color = (color is null) ? IndexedColor(colorIndex) : (SKColor)color; this.lineWidth = lineWidth; this.markerSize = markerSize; this.fontName = fontName; this.fontSize = fontSize; this.label = label; paint = new SKPaint { IsAntialias = true, Color = this.color }; }
public SkiaSharpBitmapTools(string filename, SKSize?baseSize, SKColor?tintColor, ILogger logger) : base(filename, baseSize, tintColor, logger) { var sw = new Stopwatch(); sw.Start(); bmp = SKBitmap.Decode(filename); sw.Stop(); Logger?.Log($"Open RASTER took {sw.ElapsedMilliseconds}ms ({filename})"); }
public SVGImaggeButton() : base() { svgLoaded = false; svgLoading = false; isDisposing = false; svg = new SVG.SKSvg(); previousColor = new SKColor(); previousBounds = new Rectangle(); bitmap = new SKBitmap(); canvas = new SKCanvas(bitmap); scale = SKMatrix.MakeScale(1, 1); this.MeasureInvalidated += OnMeasureInvalidated; }
/// <summary> /// Creates a new atom object. Default parameters used if arguments omitted. /// </summary> /// <param name="symbol">Symbol, default <code>C</code>C/param> /// <param name="x">Pixel x-coordinate of object</param> /// <param name="y">Pixel y-coordinate of object</param> /// <param name="fontFamily">Font family of text</param> /// <param name="fontSize">Font size of text</param> /// <param name="colour">Font colour</param> public Atom(string symbol = "C", float x = 0, float y = 0, SKColor?colour = null, string fontFamily = "Arial", float fontSize = 16, int charge = 0, int loneElectronCount = 0, float electronAngle = 0f) { DiagramID = Program.DForm.CurrentDiagram.NextFreeID(); X = x; Y = y; Symbol = symbol; FontFamily = fontFamily; FontSize = fontSize; Colour = (colour == null ? DefaultColour : colour.Value); Charge = charge; LoneElectronCount = loneElectronCount; ElectronAngle = electronAngle; }
public SkiaSharpSvgTools(string filename, SKSize?baseSize, SKColor?backgroundColor, SKColor?tintColor, ILogger logger) : base(filename, baseSize, backgroundColor, tintColor, logger) { var sw = new Stopwatch(); sw.Start(); svg = new SKSvg(); svg.Load(filename); sw.Stop(); Logger?.Log($"Open SVG took {sw.ElapsedMilliseconds}ms ({filename})"); }
private void DrawDominoBorder(SKCanvas canvas, EditingDominoVM vm) { var shape = vm.domino; var c = vm.StoneColor; var dp = vm.CanvasPoints; // is the domino visible at all? // todo: speed up this call var inside = dp.Select(x => new Avalonia.Point(x.X, x.Y)).Sum(x => Bounds.Contains(PointToDisplayAvaloniaPoint(x)) ? 1 : 0); if (inside > 0) { var path = new SKPath(); path.MoveTo(PointToDisplaySkiaPoint(dp[0])); foreach (var line in dp.Skip(0)) { path.LineTo(PointToDisplaySkiaPoint(line)); } path.Close(); SKColor?borderColor = null; if (vm.State.HasFlag(EditingDominoStates.PasteHighlight)) { borderColor = pasteHightlightColor; } if (vm.State.HasFlag(EditingDominoStates.Selected)) { borderColor = selectedBorderColor; } if (vm.State.HasFlag(EditingDominoStates.DeletionHighlight)) { borderColor = deletionHighlightColor; } if (borderColor != null) { canvas.DrawPath(path, new SKPaint() { Color = (SKColor)borderColor, IsAntialias = true, IsStroke = true, StrokeWidth = Math.Max(BorderSize, 2) * zoom, PathEffect = SKPathEffect.CreateDash(new float[] { 8 * zoom, 2 * zoom }, 10 * zoom) }); } else { if (BorderSize > 0) { canvas.DrawPath(path, new SKPaint() { Color = unselectedBorderColor, IsAntialias = true, IsStroke = true, StrokeWidth = BorderSize / 2 * zoom }); } } } }
private static SKBitmap CreateBitmap(SKSvg svg, SKColor?background = null) { // create and draw the bitmap var bmp = new SKBitmap((int)svg.CanvasSize.Width, (int)svg.CanvasSize.Height); using (var canvas = new SKCanvas(bmp)) { canvas.Clear(background ?? SKColors.Transparent); canvas.DrawPicture(svg.Picture); canvas.Flush(); } return(bmp); }
public override void Use(Layer activeLayer, Layer previewLayer, IEnumerable <Layer> allLayers, IReadOnlyList <Coordinates> recordedMouseMovement, SKColor color) { int thickness = Toolbar.GetSetting <SizeSetting>("ToolSize").Value; SKColor?fillColor = null; if (Toolbar.GetSetting <BoolSetting>("Fill").Value) { var temp = Toolbar.GetSetting <ColorSetting>("FillColor").Value; fillColor = new SKColor(temp.R, temp.G, temp.B, temp.A); } var dirtyRect = CreateRectangle(previewLayer, color, fillColor, recordedMouseMovement, thickness); ReportCustomSessionRect(SKRectI.Create(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height)); }
private void AnimateToToggle() { isAnimating = true; new Animation((value) => { double colorPartWeight = 1 - value; animatedBgColor = SkiaTools.CalculateWeightedColor(SwitchBackgroundColor, ToggledBackgroundColor, colorPartWeight, value); PrimaryCanvas.InvalidateSurface(); }).Commit(this, "bgcolorAnimation", length: (uint)250, repeat: () => false); new Animation((value) => { buttonPosition.X = 30 + (float)(value * 60.0); }).Commit(this, "positionAnimation", length: (uint)250, repeat: () => false, finished: (v, c) => { buttonPosition.X = 90.0f; isAnimating = false; }); }
public SkiaSharpTools(string filename, SKSize?baseSize, SKColor?tintColor, ILogger logger) { Logger = logger; Filename = filename; BaseSize = baseSize; if (tintColor is SKColor tint) { Logger?.Log($"Detected a tint color of {tint}"); Paint = new SKPaint { ColorFilter = SKColorFilter.CreateBlendMode(tint, SKBlendMode.SrcIn) }; } }
public byte[] Preview(byte[] imageData, float?imageScale = null, SKColor?imageMaskColor = null, SKColor?backgroundColor = null, float?cornerRadius = null, SKSizeI?size = null) { var bitmap = DrawService.CreateBitmapIcon( imageData, imageScale, imageMaskColor, backgroundColor, cornerRadius, size ?? new SKSizeI(256, 256)); var data = bitmap.ToByteArray(); bitmap.Dispose(); return(data); }
protected override void drawChart(SKCanvas canvas, int width, int height) { var ordered = DataSource.OrderByDescending(d => d.Value).ToList(); var totalAmount = GetTotalValue(); var curRad = 0d; using (SKPaint paint = new SKPaint()) { paint.Color = SKColors.White; canvas.DrawRect(0, 0, width, height, paint); } SKColor?previousColor = null; var chartRect = GetChartRect(width, height); bool done = false; for (var i = 0; i < ordered.Count; i++) { var el = ordered[i]; var label = el.Label; var radian = (el.Value / totalAmount) * 360.0; var colorHex = ColorPaletteHex[i % ColorPaletteHex.Count]; var color = SKColor.Parse(colorHex); if (i > 0 && i + 1 == MaxSlicesToShow) { var remainingElements = ordered.GetRange(i, ordered.Count - i - 1); var total = remainingElements.Sum(d => d.Value); radian = (total / totalAmount) * 360.0; if (radian + curRad != 0) { radian = 360 - curRad; } done = true; label = "Other"; } drawSlice(curRad, radian, canvas, color, width, height, chartRect); drawLegendEntry(canvas, label, color, i, chartRect); curRad += radian; previousColor = color; if (done) { break; } } }
private static SKBitmap CreateSvgBitmap(string svgData, SKColor?background = null) { // open the SVG var svg = new SKSvg(); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { writer.Write(svgData); writer.Flush(); stream.Position = 0; svg.Load(stream); } return(CreateBitmap(svg, background)); }
public SKBitmap CreateBitmapIcon(byte[] imageData, float?imageScale = null, SKColor?imageMaskColor = null, SKColor?backgroundColor = null, float?cornerRadius = null, SKSizeI?resolution = null) { var isSvg = Encoding.UTF8.GetString(imageData)[0] == '<'; SKSizeI backgroundSize; if (resolution == null) { var bitmap = GetSKBitmap(imageData, isSvg); backgroundSize = new SKSizeI(bitmap.Width, bitmap.Height); } else { backgroundSize = resolution.Value; } if (imageScale != null && imageScale > 1) { imageScale = 1; } if (imageScale != null && imageScale < 0) { imageScale = 0; } if (cornerRadius != null && cornerRadius > 1) { cornerRadius = 1; } if (cornerRadius != null && cornerRadius < 0) { cornerRadius = 0; } var pictureSize = new SKSizeI( (int)((imageScale ?? 1) * backgroundSize.Width), (int)((imageScale ?? 1) * backgroundSize.Height)); var result = DrawBitmapIcon(imageData, isSvg, pictureSize, backgroundSize, imageMaskColor, backgroundColor, cornerRadius); return(result); }
public Line(float x1 = 0, float y1 = 0, float x2 = 0, float y2 = 0, List <float[]> controlPoints = null, float thickness = 1.5f, SKColor?colour = null, LineType typeOfLine = LineType.Line, LineStyle styleOfLine = LineStyle.Plain, EndType headType = EndType.Plain, EndType tailType = EndType.Plain, int anchorID1 = -1, int anchorID2 = -1) { DiagramID = Program.DForm.CurrentDiagram.NextFreeID(); X1 = x1; Y1 = y1; X2 = x2; Y2 = y2; Thickness = thickness; Colour = (colour == null) ? DefaultColour : colour.Value; ControlPoints = (controlPoints == null) ? new List <float[]>() : controlPoints; TypeOfLine = typeOfLine; StyleOfLine = styleOfLine; HeadType = headType; TailType = tailType; AnchorID1 = anchorID1; AnchorID2 = anchorID2; }
public Dictionary <string, byte[]> FromData(byte[] imageData, float?imageScale = null, SKColor?imageMaskColor = null, SKColor?backgroundColor = null, float?cornerRadius = null) { var result = new Dictionary <string, byte[]>(); foreach (var size in _iconSizes) { var bitmap = DrawService.CreateBitmapIcon( imageData, imageScale, imageMaskColor, backgroundColor, cornerRadius, size.Value); result[size.Key] = bitmap.ToByteArray(); bitmap.Dispose(); } return(result); }