public SkiaGraphicsView(IDrawable?drawable = null) { _canvas = new SkiaCanvas(); _scalingCanvas = new ScalingCanvas(_canvas); Drawable = drawable; PaintSurface += OnPaintSurface; }
private void skglControl1_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs e) { double angleFraction = trackbarAngle.Value / (double)trackbarAngle.Maximum; double angleRadians = 2 * Math.PI * angleFraction; float angleDegrees = (float)(angleRadians * 180 / Math.PI); float fontSize = 96; string fontName = "Impact"; ICanvas canvas = new SkiaCanvas() { Canvas = e.Surface.Canvas }; canvas.FillColor = Colors.Navy; canvas.FillRectangle(0, 0, skglControl1.Width, skglControl1.Height); Microsoft.Maui.Graphics.SizeF stringSize = GraphicsPlatform.CurrentService.GetStringSize(tbText.Text, fontName, fontSize); float rectWidth = stringSize.Width; float rectHeight = stringSize.Height; Microsoft.Maui.Graphics.PointF[] rectCorners = { new(0, 0), new(rectWidth, 0), new(rectWidth, rectHeight), new(0, rectHeight), };
async void showPbf(string path, string stylePath, double zoom, double size = 512, double scale = 1) { var watch = System.Diagnostics.Stopwatch.StartNew(); // load style and font var style = new VectorTileRenderer.Style(stylePath); style.FontFallbackDirectory = mainDir + @"styles/fonts/"; // set pbf as tile provider var provider = new VectorTileRenderer.Sources.PbfTileSource(path); style.SetSourceProvider(0, provider); // render it on a skia canvas var canvas = new SkiaCanvas(); var bitmapR = await Renderer.Render(style, canvas, 0, 0, zoom, size, size, scale); demoImage.Source = bitmapR; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine(elapsedMs + "ms time"); }
public override PureImage GetTileImage(GPoint pos, int zoom) { var newY = (int)Math.Pow(2, zoom) - pos.Y - 1; var canvas = new SkiaCanvas(); System.Windows.Media.Imaging.BitmapSource bitmapSource; try { bitmapSource = Renderer.RenderCached(cachePath, style, canvas, (int)pos.X, (int)newY, zoom, 256, 256, 1).Result; } catch (Exception) { bitmapSource = null; } if (bitmapSource == null) { bitmapSource = System.Windows.Media.Imaging.BitmapImage.Create( 2, 2, 96, 96, System.Windows.Media.PixelFormats.Indexed1, new System.Windows.Media.Imaging.BitmapPalette(new List <System.Windows.Media.Color> { System.Windows.Media.Colors.Transparent }), new byte[] { 0, 0, 0, 0 }, 1); } return(GetTileImageFromArray(GetBytesFromBitmapSource(bitmapSource))); }
async void zurichMbTilesHybridStyle() { var watch = System.Diagnostics.Stopwatch.StartNew(); // load style and font var style = new VectorTileRenderer.Style(mainDir + @"styles/hybrid-style.json"); style.FontFallbackDirectory = mainDir + @"styles/fonts/"; // set pbf as tile provider var vectorProvider = new VectorTileRenderer.Sources.PbfTileSource(mainDir + @"tiles/zurich.pbf.gz"); style.SetSourceProvider(0, vectorProvider); // load raster source var rasterProvider = new VectorTileRenderer.Sources.RasterTileSource(mainDir + @"tiles/zurich.jpg"); style.SetSourceProvider("satellite", rasterProvider); // render it on a skia canvas var canvas = new SkiaCanvas(); var bitmapR = await Renderer.Render(style, canvas, 0, 0, 14, 256, 256, 1); demoImage.Source = bitmapR; watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine(elapsedMs + "ms time"); }
private void SKElement_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs e) { ICanvas canvas = new SkiaCanvas() { Canvas = e.Surface.Canvas }; //canvas.FillColor = Colors.Transparent; //canvas.FillColor = Colors.White.WithAlpha(0.9f); //canvas.FillRectangle(0, 0, (float)DrawSurface.ActualWidth, (float)DrawSurface.ActualHeight); //canvas.StrokeColor = Colors.Red.WithAlpha(.5f); canvas.StrokeColor = Colors.Red; canvas.StrokeSize = 2; var path = new PathF(); if (_points.Count > 0) { path.MoveTo(_points[0].X, _points[0].Y); for (int i = 1; i < _points.Count; i++) { path.LineTo(_points[i].X, _points[i].Y); } //path.Close(); canvas.DrawPath(path); } }
public SkiaGraphicsView(Context context, IDrawable drawable = null) : base(context) { _scale = Resources.DisplayMetrics.Density; _canvas = new SkiaCanvas(); _scalingCanvas = new ScalingCanvas(_canvas); Drawable = drawable; }
public SkiaGraphicsView(EvasObject parent, IDrawable drawable = null) : base(parent) { _canvas = new SkiaCanvas(); _scalingCanvas = new ScalingCanvas(_canvas); Drawable = drawable; PaintSurface += OnPaintSurface; IgnorePixelScaling = true; }
private void keyPicker_SelectedIndexChanged(object sender, EventArgs e) { if (keyPicker.SelectedIndex > -1) { this.scaleDiagramRenderer.GuitarModel.SetKey(keyPicker.SelectedItem.ToString()); SkiaCanvas.InvalidateSurface(); SetPageTitle(); } }
private void skglControl1_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs e) { ICanvas canvas = new SkiaCanvas() { Canvas = e.Surface.Canvas }; ActiveModel.Draw(canvas, skglControl1.Width, skglControl1.Height); }
private void OnPaintSurface(SKCanvas skCanvas, int width, int height) { var skiaCanvas = new SkiaCanvas(skCanvas); foreach (Shape shape in SampleShapes()) { skiaCanvas.DrawShape(shape); } }
private void ScalePicker_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (scalePicker.SelectedIndex > -1) { var scale = (Webprofusion.Scalex.Music.ScaleItem)scalePicker.SelectedItem; _guitarModel.SetScale(scale.ID); SkiaCanvas.Invalidate(); //SetPageTitle(); } }
private void tuningPicker_SelectedIndexChanged(object sender, EventArgs e) { if (tuningPicker.SelectedIndex > -1) { var tuning = (Webprofusion.Scalex.Guitar.GuitarTuning)tuningPicker.SelectedItem; this.scaleDiagramRenderer.GuitarModel.SetTuning(tuning.ID); SkiaCanvas.InvalidateSurface(); SetPageTitle(); } }
private void scalePicker_SelectedIndexChanged(object sender, EventArgs e) { if (scalePicker.SelectedIndex > -1) { var scale = (Webprofusion.Scalex.Music.ScaleItem)scalePicker.SelectedItem; this.scaleDiagramRenderer.GuitarModel.SetScale(scale.ID); SkiaCanvas.InvalidateSurface(); SetPageTitle(); } }
private void TuningPicker_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (tuningPicker.SelectedIndex > -1) { var tuning = (Webprofusion.Scalex.Guitar.GuitarTuning)tuningPicker.SelectedItem; _guitarModel.SetTuning(tuning.ID); SkiaCanvas.Invalidate(); // SetPageTitle(); } }
private void typePicker_SelectedIndexChanged(object sender, EventArgs e) { if (typePicker.SelectedIndex > -1) { var chordType = (Webprofusion.Scalex.Music.ChordDefinition)typePicker.SelectedItem; chordDiagramRenderer.CurrentChordDiagrams = chordDiagramRenderer.GuitarModel.GetChordDiagramsByGroup(chordType.ShortName); SkiaCanvas.InvalidateSurface(); SetPageTitle(); } }
private void skglControl1_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs e) { float width = skglControl1.Width; float height = skglControl1.Height; ICanvas canvas = new SkiaCanvas() { Canvas = e.Surface.Canvas }; canvas.FillColor = Color.FromArgb("#003366"); canvas.FillRectangle(0, 0, width, height); canvas.FillColor = Colors.LightGreen; canvas.FillRectangle(0, 0, width * LevelFraction, height); }
async void showMbTiles(string path, string stylePath, int minX, int minY, int maxX, int maxY, int zoom, double size = 512, double scale = 1) { var watch = System.Diagnostics.Stopwatch.StartNew(); // load style and font var style = new VectorTileRenderer.Style(stylePath); style.FontDirectory = mainDir + @"styles/fonts/"; // set pbf as tile provider var provider = new VectorTileRenderer.Sources.MbTilesSource(path); style.SetSourceProvider(0, provider); BitmapSource[,] bitmapSources = new BitmapSource[maxX - minX + 1, maxY - minY + 1]; // loop through tiles and render them Parallel.For(minX, maxX + 1, (int x) => { Parallel.For(minY, maxY + 1, async(int y) => { var canvas = new SkiaCanvas(); var bitmapR = await Renderer.Render(style, canvas, x, y, zoom, size, size, scale); if (bitmapR == null) { } bitmapSources[x - minX, maxY - y] = bitmapR; }); }); // merge the tiles and show it var bitmap = mergeBitmaps(bitmapSources); demoImage.Source = bitmap; scrollViewer.Background = new SolidColorBrush(style.GetBackgroundColor(zoom)); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine(elapsedMs + "ms time"); }
public byte[] GetTile(TileInfo tileInfo) { //var newY = (int)Math.Pow(2, zoom) - pos.Y - 1; var canvas = new SkiaCanvas(); System.Windows.Media.Imaging.BitmapSource bitmapSource; try { bitmapSource = Renderer.RenderCached(cachePath, style, canvas, (int)tileInfo.Index.Col, (int)tileInfo.Index.Row, Convert.ToInt32(tileInfo.Index.Level), 256, 256, 1).Result; } catch { return(null); } return(GetBytesFromBitmapSource(bitmapSource)); }
private void PositionElements(double yPos) { // calculate x pos ProfileLogo.TranslationX = Math.Min(Math.Max(ProfileExpandedX - yPos * XStep, 10), ProfileExpandedX); ProfileLogo.TranslationY = Math.Max(ProfileExpandedY - yPos * YStep, 0); ProfileLogo.Scale = Math.Min(Math.Max(2 - yPos * ScaleStep, 1), 2); // calculate header pos based on yPos currentHeaderHeight = (float)Math.Max(minHeaderHeight, SkiaCanvas.Height - yPos); SkiaCanvas.InvalidateSurface(); // change header curve //float calccurveOffset = (float)Math.Max(curveMax - yPos, curveMin); //if (calccurveOffset > 250) // calccurveOffset = 250; //if (calccurveOffset != curveOffset) //{ // curveOffset = calccurveOffset; // SkiaCanvas.InvalidateSurface(); //} }
private void SKElement_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs e) { ICanvas canvas = new SkiaCanvas() { Canvas = e.Surface.Canvas }; canvas.StrokeColor = Colors.Red; canvas.StrokeSize = 2; //draw many points var path = new PathF(); if (_points.Count > 0) { path.MoveTo(_points[0].X, _points[0].Y); for (int i = 1; i < _points.Count; i++) { path.LineTo(_points[i].X, _points[i].Y); } canvas.DrawPath(path); } }
public SkiaGraphicsView(IDrawable drawable = null) { _canvas = new SkiaCanvas(); _scalingCanvas = new ScalingCanvas(_canvas); Drawable = drawable; }
void Handle_ValueChanged(object sender, Xamarin.Forms.ValueChangedEventArgs e) { SkiaCanvas.InvalidateSurface(); }
void MySlider_ValueChanged(object sender, ValueChangedEventArgs e) { SkiaCanvas.InvalidateSurface(); }