Code

C#

Text Rendering

Beginner Draw and measure text using SKFont and SKPaint — fill, stroke, bold, italic, and baseline alignment. SKFont API

Hello, SkiaSharp!Bold ItalicStroked Text
Measured
using SkiaSharp;

SKCanvas canvas = /* ... */;
canvas.Clear(SKColors.White);

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

// ── Default typeface, 32 pt ───────────────────
using var font = new SKFont(SKTypeface.Default, 32);
paint.Color = SKColors.DarkSlateGray;
canvas.DrawText("Hello, SkiaSharp!", 20, 60, font, paint);

// ── Bold italic typeface ──────────────────────
using var boldFont = new SKFont(
    SKTypeface.FromFamilyName(
        "Arial", SKFontStyle.BoldItalic),
    28);
paint.Color = new SKColor(79, 70, 229);
canvas.DrawText("Bold Italic", 20, 120, boldFont, paint);

// ── Stroked text ──────────────────────────────
paint.Style       = SKPaintStyle.Stroke;
paint.StrokeWidth = 1.5f;
paint.Color       = new SKColor(225, 29, 72);
canvas.DrawText("Stroked Text", 20, 180, font, paint);

// ── Measure text width ────────────────────────
paint.Style = SKPaintStyle.Fill;
paint.Color = SKColors.Black;

float textWidth = font.MeasureText("Measured");
// Draw an underline the exact width of the text
canvas.DrawRect(20, 205, textWidth, 3, paint);
canvas.DrawText("Measured", 20, 240, font, paint);
Key APIs
  • new SKFont(SKTypeface, size) — create a font at a given point size
  • SKTypeface.Default — system default typeface
  • SKTypeface.FromFamilyName("Arial", SKFontStyle.Bold) — specific family & style
  • canvas.DrawText(text, x, y, font, paint) — draw at baseline position
  • font.MeasureText(text) — advance width of a string
  • font.GetGlyphWidths(text, paint) — per-glyph widths
  • paint.Style = Stroke — outline-only text
Try in SkiaSharp Fiddle