Svg.Skia is the main runtime rendering package in this repository. It loads SVG content into a SkiaSharp.SKPicture, preserves the intermediate model and drawable tree, and adds export and hit-testing helpers around that workflow.
dotnet add package Svg.Skia
SkiaSharp,SkiaSharp.SKPicture,VectorDrawable input support.| Type | Role |
|---|---|
SKSvg |
Main load, render, save, hit-test, and rebuild entry point |
SkiaModel |
Converts the intermediate ShimSkiaSharp model to real SkiaSharp objects |
SKSvgSettings |
Controls color-space and font-resolution behavior |
ITypefaceProvider |
Plug-in point for custom typeface lookup |
SkiaSvgAssetLoader |
Svg.Model asset-loader implementation for images and fonts |
SKSvg.SvgDocument.Picture for drawing.Model and Drawable.using SkiaSharp;
using Svg.Skia;
using var svg = new SKSvg();
if (svg.Load("Assets/icon.svg") is { } picture)
{
using var surface = SKSurface.Create(new SKImageInfo(256, 256));
surface.Canvas.Clear(SKColors.Transparent);
surface.Canvas.DrawPicture(picture);
}
SKSvg.Load(...) auto-detects .svg, .svgz, and Android VectorDrawable XML when loading from a file path.
Svg.Skia is the package to choose when rendering should end in a file or stream.
using SkiaSharp;
using Svg.Skia;
using var svg = new SKSvg();
if (svg.Load("Assets/icon.svg") is not null)
{
svg.Save("artifacts/icon.png", SKColors.Transparent, SKEncodedImageFormat.Png, 100, 2f, 2f);
svg.Picture?.ToPdf("artifacts/icon.pdf", SKColors.White, 1f, 1f);
svg.Picture?.ToXps("artifacts/icon.xps", SKColors.White, 1f, 1f);
}
Use this package instead of a UI package when the output target is not an Avalonia control.
SKSvg keeps both the intermediate model and the drawable tree, which makes it the best runtime package for inspection-oriented scenarios.
using System.Linq;
using ShimSkiaSharp;
using Svg.Skia;
using var svg = new SKSvg();
if (svg.Load("Assets/icon.svg") is not null)
{
var hit = svg.HitTestElements(new SKPoint(24, 24)).FirstOrDefault();
if (hit is not null)
{
Console.WriteLine(hit.ID);
}
var rebuilt = svg.RebuildFromModel();
}
Use TryGetPicturePoint or TryGetPictureRect when the pointer coordinates come from a transformed canvas rather than picture space.
Svg.Skia also handles Android drawable XML directly:
using Svg.Skia;
using var svg = new SKSvg();
if (svg.LoadVectorDrawable("Assets/icon.xml") is not null)
{
svg.Save("artifacts/icon.png", SkiaSharp.SKColors.Transparent);
}
If you only need the parsed SVG document produced from a VectorDrawable, see Svg.Model.
SKSvgSettings controls the rendering conversion layer. The default configuration includes:
Add custom ITypefaceProvider implementations when your application resolves fonts from embedded assets, custom directories, or a separate font registry.
Svg.SkiaSkiaSharp.SKPicture wrapper yet.