Search code examples
xamarinxamarin.formsskiasharpskia

Is there a simple way of handling (transforming) a group of objects in SkiaSharp?


In a nutshell, let's say, I need to draw a complex object (arrow) which consists of certain amount of objects, like five (or more) lines, for instance. And what's more important, that object must be transformed with particular (dynamic) coordinates (including scaling, possibly).

My question is whether SkiaSharp has anything which I can use for manipulating of this complex object transformation (some sort of grouping etc.) or do I still need to calculate every single point manually (with matrix, for instance).

This question is related particularly to SkiaSharp as I use it on Xamarin, but maybe some general answers from Skia can also help with it?


I think, the question might be too common (and possibly not for stackoverflow exactly), but I just can't find any specific information in google.

Yes, I know how to use SkiaSharp for drawing primitives.


Solution

  • create an SKPath and add lines and other shapes to it

    SKPath path = new SKPath();
    path.LineTo(...);
    ... 
    ...
    

    then draw the SKPath on your canvas

    canvas.DrawPath(path,paint);
    

    you can apply a transform to the entire path before drawing

    var rot = new SKMatrix();
    SKMatrix.RotateDegrees(ref rot, 45.0f);
    path.Transform(rot);