Code

C#

Basic Shapes

Beginner Draw rectangles, circles, ovals, lines, and rounded rects on an SKCanvas. SkiaSharp Docs

using SkiaSharp;

using var surface = SKSurface.Create(
    new SKImageInfo(400, 300));
SKCanvas canvas = surface.Canvas;
canvas.Clear(SKColors.White);

using var paint = new SKPaint
    { IsAntialias = true };

// Filled rectangle — indigo
paint.Style = SKPaintStyle.Fill;
paint.Color  = new SKColor(79, 70, 229);
canvas.DrawRect(20, 20, 120, 80, paint);

// Stroked rectangle — red
paint.Style       = SKPaintStyle.Stroke;
paint.StrokeWidth = 3;
paint.Color       = new SKColor(225, 29, 72);
canvas.DrawRect(160, 20, 120, 80, paint);

// Line — green
paint.StrokeWidth = 4;
paint.Color = new SKColor(22, 163, 74);
canvas.DrawLine(20, 145, 290, 145, paint);

// Filled circle — amber
paint.Style = SKPaintStyle.Fill;
paint.Color = new SKColor(245, 158, 11);
canvas.DrawCircle(80, 225, 50, paint);

// Stroked oval — sky blue
paint.Style       = SKPaintStyle.Stroke;
paint.StrokeWidth = 3;
paint.Color       = new SKColor(14, 165, 233);
canvas.DrawOval(220, 225, 70, 40, paint);

// Rounded rectangle — pink
paint.Style = SKPaintStyle.Fill;
paint.Color = new SKColor(219, 39, 119);
canvas.DrawRoundRect(320, 20, 60, 50, 12, 12, paint);
Key APIs
  • canvas.Clear(SKColors.White) — fill the background
  • canvas.DrawRect(x, y, w, h, paint) — axis-aligned rectangle
  • canvas.DrawCircle(cx, cy, radius, paint) — perfect circle
  • canvas.DrawOval(cx, cy, rx, ry, paint) — ellipse
  • canvas.DrawLine(x0, y0, x1, y1, paint) — straight line
  • canvas.DrawRoundRect(x, y, w, h, rx, ry, paint) — rounded corners
  • paint.StyleFill, Stroke, or StrokeAndFill
  • paint.IsAntialias = true — smooth edges
Try in SkiaSharp Fiddle