Code

C#

Gradients

Intermediate Apply linear, radial, and sweep gradient shaders via SKShader assigned to SKPaint.Shader. SKShader API

Linear GradientRadialSweep
using SkiaSharp;

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

// ── Linear gradient ───────────────────────────
paint.Shader = SKShader.CreateLinearGradient(
    new SKPoint(0, 50),
    new SKPoint(400, 50),
    new[] {
        new SKColor(79,  70, 229),  // indigo
        new SKColor(219, 39, 119),  // pink
    },
    null,
    SKShaderTileMode.Clamp);

canvas.DrawRect(20, 20, 360, 70, paint);
paint.Shader?.Dispose();

// ── Radial gradient ───────────────────────────
paint.Shader = SKShader.CreateRadialGradient(
    new SKPoint(120, 200),
    75,
    new[] {
        SKColors.LightYellow,
        new SKColor(245, 158, 11),  // amber
        SKColors.OrangeRed,
    },
    new[] { 0f, 0.5f, 1f },
    SKShaderTileMode.Clamp);

canvas.DrawCircle(120, 200, 75, paint);
paint.Shader?.Dispose();

// ── Sweep gradient ────────────────────────────
paint.Shader = SKShader.CreateSweepGradient(
    new SKPoint(300, 200),
    new[] {
        SKColors.Cyan,
        SKColors.Magenta,
        SKColors.Yellow,
        SKColors.Cyan,
    },
    null);

canvas.DrawCircle(300, 200, 70, paint);
paint.Shader?.Dispose();
Key APIs
  • SKShader.CreateLinearGradient(start, end, colors, colorPos, tileMode)
  • SKShader.CreateRadialGradient(center, radius, colors, colorPos, tileMode)
  • SKShader.CreateSweepGradient(center, colors, colorPos) — angular / conic
  • SKShaderTileMode.Clamp — edge color outside bounds; also Repeat, Mirror
  • paint.Shader?.Dispose() — always dispose the shader object after use
  • Combine gradients with SKShader.CreateCompose for layered effects
Try in SkiaSharp Fiddle