Code

C#

Transforms

Intermediate Translate, rotate, scale, and skew the canvas matrix — always bracket changes with Save / Restore. SKCanvas API

TranslateRotate 45°Scale(2, 0.75)Skew
using SkiaSharp;

SKCanvas canvas = /* ... */;
using var paint = new SKPaint
    { IsAntialias = true, Style = SKPaintStyle.Fill };

// ── Translate ─────────────────────────────────
canvas.Save();
canvas.Translate(80, 80);        // move origin

paint.Color = new SKColor(79, 70, 229);
canvas.DrawRect(-40, -40, 80, 80, paint); // centred
canvas.Restore();

// ── Rotate 45° around centre of next rect ─────
canvas.Save();
canvas.Translate(240, 80);
canvas.RotateDegrees(45);        // pivot = current origin

paint.Color = new SKColor(225, 29, 72);
canvas.DrawRect(-40, -40, 80, 80, paint);
canvas.Restore();

// ── Scale ─────────────────────────────────────
canvas.Save();
canvas.Translate(80, 230);
canvas.Scale(2f, 0.75f);         // stretch x, squash y

paint.Color = new SKColor(22, 163, 74);
canvas.DrawCircle(0, 0, 30, paint);
canvas.Restore();

// ── Skew ──────────────────────────────────────
canvas.Save();
canvas.Translate(290, 215);
canvas.Skew(0.45f, 0);           // horizontal shear

paint.Color = new SKColor(245, 158, 11);
canvas.DrawRect(-30, -30, 80, 60, paint);
canvas.Restore();

// Tip: canvas.SetMatrix(SKMatrix.Identity)
// resets the entire transform at once.
Key APIs
  • canvas.Save() / canvas.Restore() — push/pop the transform stack
  • canvas.Translate(tx, ty) — move the coordinate origin
  • canvas.RotateDegrees(deg) / RotateRadians(rad) — rotate around the origin
  • canvas.Scale(sx, sy) — non-uniform scaling
  • canvas.Skew(kx, ky) — shear the coordinate system
  • canvas.SetMatrix(SKMatrix) — replace the entire transform
  • canvas.TotalMatrix — read the current accumulated matrix
Try in SkiaSharp Fiddle