Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to accept screen operations even if repainting takes long time processing?

$
0
0

I have to do very heavy processing when updating SKCanvasView.
At that time, the UI thread stops every time.
So, I'd like to implement it using asynchronous processing, but would you please teach me?

XAML:

 <Grid>
    <skia:SKCanvasView x:Name="canvasView" PaintSurface="OnPaintCanvas" EnableTouchEvents="True" Touch="OnTouch"/>
 </Grid>

Code Behind:

 private void OnPaintCanvas(object sender, SKPaintSurfaceEventArgs e)
    {
        SKImageInfo info = e.Info;
        SKSurface surface = e.Surface;
        SKCanvas canvas = surface.Canvas;

        int surfaceWidth = info.Width;
        int surfaceHeight = info.Height;
        SKPoint surfaceSize = new SKPoint(surfaceWidth, surfaceHeight);

        canvas.Clear(PaintColors.DefaultBackground);

        if (!prevSurfaceSize.Equals(surfaceSize) || canvasRepaintFlag)
        {
            //Debug.WriteLine("Repaint");
            //Re-painting everything when the surface size changes, or when canvasRepaintFlag is True
            layerA = new Canvas((int)surfaceSize.X, (int)surfaceSize.Y);

            //Convert Vectormap to Bitmap and paint Bitmap for paintings (very heavy)
            canvas.DrawBitmap(vectormap.ToBitmap(layerA), 0, 0);

            canvasRepaintFlag = false;
        }...
    }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>