Svg.Skia is the main runtime rendering package in this repository. It loads SVG content into a SkiaSharp.SKPicture, keeps the authored SvgDocument, retained SvgSceneDocument, and intermediate command model available, and adds export, interaction, hit-testing, and animation 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 |
SvgSceneDocument |
Compiled retained scene used for hit testing, subtree rendering, and incremental refresh |
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 |
SvgInteractionDispatcher |
Framework-neutral pointer routing and cursor-resolution helper |
SvgAnimationHostBackend |
Shared host playback backend enum used by the UI packages |
SKSvg.SvgDocument.Picture for drawing.SourceDocument, RetainedSceneGraph, or Model.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 the authored document, retained scene graph, and intermediate model, which makes it the best runtime package for inspection-oriented scenarios.
using System;
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();
var topmost = svg.HitTestTopmostElement(new SKPoint(24, 24));
if (hit is not null)
{
Console.WriteLine(hit.ID);
}
if (svg.TryGetRetainedSceneNodeById("layer-a", out var node) && node is not null)
{
using var subtreePicture = svg.CreateRetainedSceneNodePicture(node);
}
}
Use TryGetPicturePoint or TryGetPictureRect when the pointer coordinates come from a transformed canvas rather than picture space. Use TryApplyRetainedSceneMutationAndRender(...) or TryApplyRetainedSceneMutationByIdAndRender(...) when a localized DOM edit should refresh the current Picture without a full FromSvgDocument(...) rebuild.
For low-level command edits, mutate Model and call RebuildFromModel().
Svg.Skia now includes a shared input-routing surface through SvgInteractionDispatcher.
Use it when a host wants:
SvgElement mouse events.The dispatcher accepts SvgPointerInput and raises SvgPointerEventArgs through its Dispatched event.
SKSvg now owns the shared animation runtime for the repository.
The main members are:
HasAnimationsAnimationTimeSetAnimationTime(...)AdvanceAnimation(...)ResetAnimation()AnimationInvalidatedAnimationMinimumRenderIntervalHasPendingAnimationFrameFlushPendingAnimationFrame()LastAnimationDirtyTargetCountThe runtime also exposes SupportsNativeComposition, TryCreateNativeCompositionScene(...), and TryCreateNativeCompositionFrame(...) so host packages can attach retained playback paths without reimplementing SVG timing or property evaluation.
The shared renderer now includes layered redraw support for animation frames and a local benchmark harness under tests/Svg.Skia.Benchmarks.
That benchmark project compares:
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.