Code

C#

Image Filters

Intermediate Apply Gaussian blur, drop shadow, and colour-matrix filters via SKImageFilter and SKColorFilter. SKImageFilter API

BlurDrop ShadowGrayscaleDilate
using SkiaSharp;

SKCanvas canvas = /* ... */;
using var paint = new SKPaint
{
    IsAntialias = true,
    Color       = new SKColor(79, 70, 229),
    Style       = SKPaintStyle.Fill,
};

// ── Gaussian blur ─────────────────────────────
paint.ImageFilter =
    SKImageFilter.CreateBlur(8, 8);
canvas.DrawRect(20, 20, 120, 80, paint);
paint.ImageFilter = null;

// ── Drop shadow ───────────────────────────────
paint.ImageFilter = SKImageFilter.CreateDropShadow(
    4, 4,                         // dx, dy offset
    6, 6,                         // blur x, y sigma
    new SKColor(0, 0, 0, 150));   // shadow color
canvas.DrawRect(180, 20, 120, 80, paint);
paint.ImageFilter = null;

// ── Colour matrix — grayscale ─────────────────
var grayscale = new float[]
{
    0.21f, 0.72f, 0.07f, 0, 0,
    0.21f, 0.72f, 0.07f, 0, 0,
    0.21f, 0.72f, 0.07f, 0, 0,
    0,     0,     0,     1, 0,
};
paint.ColorFilter =
    SKColorFilter.CreateColorMatrix(grayscale);
paint.Color = new SKColor(225, 29, 72);
canvas.DrawCircle(100, 210, 55, paint);
paint.ColorFilter = null;

// ── Dilate (morphology expand) ────────────────
paint.ImageFilter =
    SKImageFilter.CreateDilate(4, 4);
paint.Color = new SKColor(22, 163, 74);
canvas.DrawCircle(280, 210, 40, paint);
paint.ImageFilter = null;
Key APIs
  • SKImageFilter.CreateBlur(sigmaX, sigmaY) — Gaussian blur
  • SKImageFilter.CreateDropShadow(dx, dy, sx, sy, color) — drop shadow
  • SKImageFilter.CreateDilate(rx, ry) / CreateErode — morphology
  • SKColorFilter.CreateColorMatrix(float[20]) — 4×5 colour transform
  • SKColorFilter.CreateHighContrast(...) — accessibility filter
  • Set paint.ImageFilter = null after each draw to reset the filter
Try in SkiaSharp Fiddle