SkiaSharp

From Yggenyk
Jump to: navigation, search

SkiaSharp

Fiddles

Disposable Transform

    using (new Transform(canvas))
    {

    }

    public class Transform : IDisposable
    {
        private readonly SKCanvas _canvas;

        public Transform(SKCanvas canvas)
        {
            _canvas = canvas;
            canvas.Save();
        }

        public void Dispose()
        {
            _canvas.Restore();
        }
    }

Transform point from current transformation matrix to original grid

    // Transform point from current transformation matrix to original grid
    var originalPoints = new[] { new SKPoint(0, 0) };
    var pointInCurrentTransformationMatrix = new[] { new SKPoint(0, 0) };
    canvas.TotalMatrix.MapPoints(originalPoints, pointInCurrentTransformationMatrix);

    // Transform point from original grid to current transformation matrix
    canvas.TotalMatrix.TryInvert(out var inverseMatrix);
    var snappedPixelPointsInCurrentTransformationMatrix = new[] { new SKPoint(0, 0) };
    inverseMatrix.MapPoints(snappedPixelPointsInCurrentTransformationMatrix, originalPoints);

Typography Line Terms.png

Clipping with Paths and Regions

WPF