How to improve the performance of drawing a large polygon using SkiaSharp?

Viewed 1047

I have a contour that has about 20,000 points that I'm drawing using SkiSharp. It's a bit sluggish (200 ms), and I'm wondering if there are any performance improvements I could make to my code:

var path = new SKPath();
path.AddPoly(contour.Select(p => p.ToSKPoint()).ToArray());  // contour is Point[]
canvas.DrawPath(path, paint);

When my view is zoomed out, it's probably not even possible to see that many points, so one possible optimization I thought about is to filter out points uniformly (like only keep one every 10 or 100 points).

2 Answers

I’ve improved my rendering time from 6ms to 1ms by using SKGLView instead of SKCanvasView. They have the same API, and are very easy to exchange.

Also, like you’ve said dynamically reducing the amount of points depending on zoom level. Aka LOD - Level of Detail.

And if feasible, disable AntiAliasing.

Try to create the SKPath only once and use it again and again. That could help.

Related