static void Main(string[] args) { var srcPath = "../Icons"; var dstPath = "../Icons.Png"; if (!Directory.Exists(dstPath)) { Directory.CreateDirectory(dstPath); } foreach (var inputPath in Directory.GetFiles(srcPath, "*.svg")) { Console.WriteLine(inputPath); using var inputStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read); var outputPath = Path.Combine(dstPath, Path.GetFileNameWithoutExtension(inputPath) + ".png"); var quality = 100; var svg = new SkiaSharp.Extended.Svg.SKSvg(); try { var pict = svg.Load(inputStream); var dimen = new SkiaSharp.SKSizeI( (int)Math.Ceiling(pict.CullRect.Width) * 5, (int)Math.Ceiling(pict.CullRect.Height) * 5 ); var matrix = SKMatrix.MakeScale(5, 5); var img = SKImage.FromPicture(pict, dimen, matrix); // convert to PNG var skdata = img.Encode(SkiaSharp.SKEncodedImageFormat.Png, quality); using (var stream = File.OpenWrite(outputPath)) { skdata.SaveTo(stream); } } catch { } } }
// create a new image from a picture public static SKImage FromPicture(SKPicture picture, SKSizeI dimensions) { return(FromPicture(picture, dimensions, null)); }
public static SKRectI Create(SKSizeI size) { return SKRectI.Create(SKPointI.Empty.X, SKPointI.Empty.Y, size.Width, size.Height); }
public SKRectI AspectFill(SKSizeI size) => Truncate(((SKRect)this).AspectFill(size));
public static SKSizeI Add(SKSizeI sz1, SKSizeI sz2) => sz1 + sz2;
public static SKPointI Add(SKPointI pt, SKSizeI sz) => pt + sz;
public static SKImageFilter CreateMatrixConvolution(SKSizeI kernelSize, float[] kernel, float gain, float bias, SKPointI kernelOffset, SKMatrixConvolutionTileMode tileMode, bool convolveAlpha, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) { if (kernel == null) throw new ArgumentNullException(nameof(kernel)); if (kernel.Length != kernelSize.Width * kernelSize.Height) throw new ArgumentException("Kernel length must match the dimensions of the kernel size (Width * Height).", nameof(kernel)); return GetObject<SKImageFilter>(SkiaApi.sk_imagefilter_new_matrix_convolution(ref kernelSize, kernel, gain, bias, ref kernelOffset, tileMode, convolveAlpha, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); }
public extern static sk_imagefilter_t sk_imagefilter_new_matrix_convolution(ref SKSizeI kernelSize, float[] kernel, float gain, float bias, ref SKPointI kernelOffset, SKMatrixConvolutionTileMode tileMode, bool convolveAlpha, sk_imagefilter_t input /*NULL*/, sk_imagefilter_croprect_t cropRect /*NULL*/);
public static SKImage FromPicture(SKPicture picture, SKSizeI dimensions, SKMatrix matrix, SKPaint paint) => FromPicture(picture, dimensions, &matrix, paint);
public static SKImage FromPicture(SKPicture picture, SKSizeI dimensions, SKPaint paint) => FromPicture(picture, dimensions, null, paint);
public static SKImage FromPicture(SKPicture picture, SKSizeI dimensions, SKMatrix matrix) => FromPicture(picture, dimensions, &matrix, null);
// create a new image from a picture public static SKImage FromPicture(SKPicture picture, SKSizeI dimensions) => FromPicture(picture, dimensions, null, null);
public readonly SKImageInfo WithSize(SKSizeI size) => WithSize(size.Width, size.Height);
public extern static void sk_codec_get_scaled_dimensions(sk_codec_t codec, float desiredScale, out SKSizeI dimensions);
public static SKPointI Add(SKPointI pt, SKSizeI sz) { return(new SKPointI(pt.X + sz.Width, pt.Y + sz.Height)); }
public static SKPointI Subtract(SKPointI pt, SKSizeI sz) { return(new SKPointI(pt.X - sz.Width, pt.Y - sz.Height)); }
public SKBitmap Resize(SKSizeI size, SKFilterQuality quality) => Resize(Info.WithSize(size), quality);
public static SKShader CreatePerlinNoiseTurbulence (float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, SKSizeI tileSize) => GetObject (SkiaApi.sk_shader_new_perlin_noise_turbulence (baseFrequencyX, baseFrequencyY, numOctaves, seed, &tileSize));
public SKPointI(SKSizeI sz) { x = sz.Width; y = sz.Height; }
public static SKPointI Subtract(SKPointI pt, SKSizeI sz) => pt - sz;
public static SKSizeI Subtract(SKSizeI sz1, SKSizeI sz2) => sz1 - sz2;
public void Inflate(SKSizeI size) { Inflate(size.Width, size.Height); }
public static SKPoint Add(SKPoint pt, SKSizeI sz) => pt + sz;
public static SKRectI Create(SKPointI location, SKSizeI size) { return SKRectI.Create(location.X, location.Y, size.Width, size.Height); }
public static SKPoint Subtract(SKPoint pt, SKSizeI sz) => pt - sz;
public static SKImage FromPicture(SKPicture picture, SKSizeI dimensions, SKMatrix matrix) { return(FromPicture(picture, dimensions, matrix, null)); }
// updates the locations at which to draw the provided points private void UpdateDrawing(SKCanvas canvas, SkiaSharp.SKSizeI displaySize) { canvas.Clear(); if (this.plotRequests.Count < 1) { return; } DateTime start = DateTime.Now; double resolution = 1; // determine what domain and range we want to display double minimumX = this.MinX.GetValueOrDefault(this.minXPresent); double maximumX = this.MaxX.GetValueOrDefault(this.maxXPresent); double minimumY = this.MinY.GetValueOrDefault(this.minYPresent); double maximumY = this.MaxY.GetValueOrDefault(this.maxYPresent); int i; double scaleX = 0; double scaleY = 0; if (maximumX > minimumX) { scaleX = displaySize.Width / (maximumX - minimumX); } if (maximumY > minimumY) { scaleY = displaySize.Height / (maximumY - minimumY); } // plot all of the provided points double x, y, x2, y2; foreach (PlotRequest plotRequest in this.plotRequests) { List <Datapoint> pointList = plotRequest.Data; if (pointList.Count < 1) { continue; } x = (pointList[0].Input - minimumX) * scaleX; y = (maximumY - pointList[0].Output) * scaleY; SKPaint brush = makeBrush(plotRequest.DrawColor); for (i = 0; i < pointList.Count; i++) { x2 = (pointList[i].Input - minimumX) * scaleX; y2 = (maximumY - pointList[i].Output) * scaleY; if (Math.Abs(x2 - x) < resolution && Math.Abs(y2 - y) < resolution) { continue; // skip any lines that the user won't be able to see } if (plotRequest.DrawData) { canvas.DrawLine((float)x, (float)y, (float)x2, (float)y2, brush); } x = x2; y = y2; } if (plotRequest.Draw_RegressionLine) { Correlator correlator = plotRequest.Correlator; if (correlator.StdDevX != 0) { // if stdDevX == 0, we'll skip it if (correlator.StdDevX != 0) { SKPaint correlatorBrush = makeBrush(plotRequest.RegressionLine_Color); // compute the equation of the least-squares regression line double correlation = correlator.Correlation; // plot the least-squares regression line double slope = correlator.Slope; x = minimumX; y = (x - correlator.MeanX) * slope + correlator.MeanY; x2 = maximumX; y2 = (x2 - correlator.MeanX) * slope + correlator.MeanY; double renderX1 = (x - minimumX) * scaleX; double renderY1 = (maximumY - y) * scaleY; double renderX2 = (x2 - minimumX) * scaleX; double renderY2 = (maximumY - y2) * scaleY; double rescaleRatio; // cut off the right side of the line if it goes out of bounds rescaleRatio = 1; if (renderY2 > displaySize.Height) { rescaleRatio = (displaySize.Height - renderY1) / (renderY2 - renderY1); } else { if (renderY2 < 0) { rescaleRatio = (renderY1) / (renderY1 - renderY2); } } renderY2 = renderY1 + (renderY2 - renderY1) * rescaleRatio; renderX2 = renderX1 + (renderX2 - renderX1) * rescaleRatio; // cut off the left side of the line if it goes out of bounds rescaleRatio = 1; if (renderY1 > displaySize.Height) { rescaleRatio = (displaySize.Height - renderY2) / (renderY1 - renderY2); } else { if (renderY1 < 0) { rescaleRatio = (renderY2) / (renderY2 - renderY1); } } renderY1 = renderY2 - (renderY2 - renderY1) * rescaleRatio; renderX1 = renderX2 - (renderX2 - renderX1) * rescaleRatio; canvas.DrawLine((float)renderX1, (float)renderY1, (float)renderX2, (float)renderY2, correlatorBrush); } } } } // now draw some tick marks if (this.XAxisSubdivisions != null) { y = displaySize.Height - 1; y2 = displaySize.Height * 19 / 20; foreach (double tickX in this.XAxisSubdivisions) { canvas.DrawLine((float)((tickX - minimumX) * scaleX), (float)y, (float)((tickX - minimumX) * scaleX), (float)y2, cyanBrush); } } if (this.YAxisSubdivisions != null) { x = 0; x2 = displaySize.Width / 20; foreach (double tickY in this.YAxisSubdivisions) { canvas.DrawLine((float)x, (float)((maximumY - tickY) * scaleY), (float)x2, (float)((maximumY - tickY) * scaleY), cyanBrush); } } // draw some axes canvas.DrawLine(0, 0, 0, displaySize.Height, cyanBrush); canvas.DrawLine(0, displaySize.Height - 1, displaySize.Width, displaySize.Height - 1, cyanBrush); DateTime end = DateTime.Now; System.Diagnostics.Debug.WriteLine("spent " + end.Subtract(start) + " in PlotView.UpdatePoints"); }