locked
About skiasharp scale RRS feed

  • Question

  • User391493 posted

    I have a question about skiasharp's scale, but what does "canvas.Scale(2);" double?

    For example, if the whole is 256x256, does "canvas.Scale(2);" result in 512x512?

    Also, I don't clearly understand the difference between SKCanvasView and SKCanvas.

    List<SKBitmap> bitmaps = new List<SKBitmap>();
    private async void Pic()
    {
    
        for (int i = 1; i <= 10; i++)
        {
            string url = "";
    
            url = "https://c.tile.openstreetmap.org/" + 18 + "/" + (233891 + i) + "/" + 100481 + ".png";
    
    
            try
            {
                var httpClient = new HttpClient();
                using (Stream stream = await httpClient.GetStreamAsync(url))
                using (MemoryStream memStream = new MemoryStream())
                {
                    await stream.CopyToAsync(memStream);
                    memStream.Seek(0, SeekOrigin.Begin);
                    //helloBitmap = SKBitmap.Decode(memStream);
                    bitmaps.Add(SKBitmap.Decode(memStream));
                }
            }
            catch(Exception e)
            {
            }
        }
    
        SKCanvasView canvasView = new SKCanvasView();
        canvasView.PaintSurface += OnCanvasViewPaintSurface;
        Content = new ScrollView { Content = canvasView, Orientation = ScrollOrientation.Horizontal };
    }
    
    private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
    {
    
        SKImageInfo info = args.Info;
        SKSurface surface = args.Surface;
        SKCanvas canvas = surface.Canvas;
    
        canvas.Scale(2);
    
        using (surface = SKSurface.Create(new SKImageInfo(1000, 1000)))
        {
            for (int i = 0; i < bitmaps.Count; i++)
            {
                canvas.DrawBitmap(bitmaps[i], 256 * i, 0, null);
            }
        }
    }
    
    Monday, June 8, 2020 1:01 AM

All replies

  • User382871 posted

    For example, if the whole is 256x256, does "canvas.Scale(2);" result in 512x512? Yes, SKCanvas.Scale method change the size of the drawing according the scale value. I don't clearly understand the difference between SKCanvasView and SKCanvas. SKCanvasView is a view that can be drawn on using SkiaSharp drawing commands, it is just like a drawing board. SKCanvas encapsulates all of the state about drawing into a device (bitmap or surface), it works like a paintbrush or a set of drawing tools.

    Tutorials: https://docs.microsoft.com/en-us/dotnet/api/skiasharp.skcanvas?view=skiasharp-1.68.1 https://docs.microsoft.com/en-us/dotnet/api/skiasharp.views.forms.skcanvasview?view=skiasharp-views-forms-1.68.1

    Tuesday, June 9, 2020 7:11 AM