How can I make a snapshot of the surface using SKSurface.Snapshot()?

579 views Asked by At

The following code breaks the code, and my App closes when I click the Button.

I tried to take a snapshot inside the method, but it crashes the App.

SKSurface CenterSurface;
void canvasView_BubbleCenterCircle(object sender, SKPaintSurfaceEventArgs e)
{
    var surface = e.Surface;
    var canvas = surface.Canvas;

    canvas.Clear(SKColors.Black);

    var width = e.Info.Width;
    var height = e.Info.Height;

    // Move the origin to the center
    canvas.Translate(width / 2, height / 2);

    canvas.DrawLine(-220, 0, 220, 0, whitePaint);
    canvas.DrawLine(0, -220, 0, 220, whitePaint);
        
    // Draw base graphics
    canvas.DrawCircle(0, 0, 180f, whitePaint);

    canvas.DrawCircle(x, y, 50f, whitePaint);
    canvas.DrawLine(x, y, x, y + 35, whitePaint);
    canvas.DrawLine(x, y - 35, x, y, whitePaint);
    canvas.DrawLine(x, y, x + 35, y, whitePaint);
    canvas.DrawLine(x - 35, y, x, y, whitePaint);

    CenterSurface = surface;       
}


private async void cameraButton_Clicked(object sender, EventArgs e)
{
    FinalCenterImage = CenterSurface.Snapshot();
    //...
}
0

There are 0 answers