Svg.Skia is an SVG rendering library.
Svg.Skia can be used as a .NET library or as a CLI application to render SVG files based on a static SVG Full 1.1 subset to raster images or to a backend's canvas.
The Svg.Skia
is using SVG library to load Svg
object model.
The Svg.Skia
library is implemented using SkiaSharp
rendering backend that aims to be on par
or more complete then original System.Drawing
implementation and more performant and cross-platform.
The Svg.Skia
can be used in same way as the SkiaSharp.Extended.Svg
(load svg
files as SKPicture
).
The Svg
library has more complete implementation of Svg
document model then SkiaSharp.Extended.Svg
and the Svg.Skia
renderer will provide more complete rendering subsystem implementation.
Svg.Skia is delivered as a NuGet package.
You can find the packages here NuGet and install the package like this:
Install-Package Svg.Skia
or by using nightly build feed:
- Add
https://www.myget.org/F/svgskia-nightly/api/v2
to your package sources - Alternative nightly build feed
https://pkgs.dev.azure.com/wieslawsoltes/GitHub/_packaging/CI/nuget/v3/index.json
- Update your package using
Svg.Skia
feed
and install the package like this:
Install-Package Svg.Skia -Pre
dotnet add package Svg.Skia
Install-Package Svg.Skia
using SkiaSharp;
using Svg.Skia;
var svg = new SKSvg();
svg.Load("image.svg");
SKCanvas canvas = ...
canvas.DrawPicture(svg.Picture);
using SkiaSharp;
using Svg.Skia;
using (var svg = new SKSvg())
{
if (svg.Load("image.svg") != null)
{
svg.Save("image.png", SKEncodedImageFormat.Png, 100, 1f, 1f);
}
}
using System.IO;
using SkiaSharp;
using Svg.Skia;
using (var svg = new SKSvg())
{
if (svg.Load("image.svg") != null)
{
using (var stream = File.OpenWrite("image.png"))
{
svg.Picture.ToImage(stream, SKColors.Empty, SKEncodedImageFormat.Png, 100, 1f, 1f);
}
}
}
using SkiaSharp;
using Svg.Skia;
using (var svg = new SKSvg())
{
if (svg.Load("image.svgz") != null)
{
svg.Save("image.png", SKEncodedImageFormat.Png, 100, 1f, 1f);
}
}
using System.IO;
using SkiaSharp;
using Svg.Skia;
using (var svg = new SKSvg())
{
if (svg.Load("image.svgz") != null)
{
using (var stream = File.OpenWrite("image.png"))
{
svg.Picture.ToImage(stream, SKColors.Empty, SKEncodedImageFormat.Png, 100, 1f, 1f);
}
}
}
using SkiaSharp;
using Svg.Skia;
using (var svg = new SKSvg())
{
if (svg.Load("image.svg") != null)
{
svg.Picture.ToPdf("image.pdf", SKColors.Empty, 1f, 1f);
}
}
using SkiaSharp;
using Svg.Skia;
using (var svg = new SKSvg())
{
if (svg.Load("image.svg") != null)
{
svg.Picture.ToXps("image.xps", SKColors.Empty, 1f, 1f);
}
}
You need to use 0.10.0-preview1
version of AvaloniaUI.
dotnet add package Svg.Skia.Avalonia
Install-Package Svg.Skia.Avalonia
<UseControl xmlns="https://github.com/avaloniaui"
xmlns:svg="clr-namespace:Svg.Skia.Avalonia;assembly=Svg.Skia.Avalonia">
<Image>
<Image.Source>
<svg:SvgImage Source="/Assets/__AJ_Digital_Camera.svg"/>
</Image.Source>
</Image>
<UserControl.Resources>
<svg:SvgImage x:Key="__tiger" Source="/Assets/__tiger.svg"/>
</UserControl.Resources>
<Image Name="svgResourceImage" Source="{DynamicResource __tiger}"/>
dotnet tool install -g Svg.Skia.Converter
Svg.Skia.Converter:
Converts a svg file to an encoded bitmap image.
Usage:
Svg.Skia.Converter [options]
Options:
-f, --inputFiles <inputfiles> The relative or absolute path to the input files
-d, --inputDirectory <inputdirectory> The relative or absolute path to the input directory
-o, --outputDirectory <outputdirectory> The relative or absolute path to the output directory
--outputFiles <outputfiles> The relative or absolute path to the output files
-p, --pattern <pattern> The search string to match against the names of files in the input directory
--format <format> The output image format
-q, --quality <quality> The output image quality
-b, --background <background> The output image background
-s, --scale <scale> The output image horizontal and vertical scaling factor
--scaleX, -sx <scalex> The output image horizontal scaling factor
--scaleY, -sy <scaley> The output image vertical scaling factor
--systemLanguage <systemlanguage> The system language name as defined in BCP 47
--quiet Set verbosity level to quiet
-c, --load-config <load-config> The relative or absolute path to the config file
--save-config <save-config> The relative or absolute path to the config file
--version Show version information
-?, -h, --help Show help and usage information
Supported formats: png, jpg, jpeg, webp, pdf, xps
To build the projects you need to install .NET Core 3.1 version SDK 3.1.102
.
git clone [email protected]:wieslawsoltes/Svg.Skia.git
cd Svg.Skia
git submodule update --init --recursive
dotnet build -c Release
cd ./src/Svg.Skia.Converter
dotnet publish -c Release -f netcoreapp3.1 -r win7-x64 /p:PublishTrimmed=True /p:PublishReadyToRun=True -o Svg.Skia.Converter_netcoreapp3.1_win7-x64
cd ./src/Svg.Skia.Converter
dotnet publish -c Release -f netcoreapp3.1 -r ubuntu.14.04-x64 /p:PublishTrimmed=True /p:PublishReadyToRun=True -o Svg.Skia.Converter_netcoreapp3.1_ubuntu.14.04-x64
cd ./src/Svg.Skia.Converter
dotnet publish -c Release -f netcoreapp3.1 -r osx.10.12-x64 /p:PublishTrimmed=True /p:PublishReadyToRun=True -o Svg.Skia.Converter_netcoreapp3.1_osx.10.12-x64
cd ./src/Svg.Skia.Converter
dotnet publish -c Release -f netcoreapp3.1 -r debian.8-x64 /p:PublishTrimmed=True /p:PublishReadyToRun=True -o Svg.Skia.Converter_netcoreapp3.1_debian.8-x64
cd ./src/SvgToPng
dotnet publish -c Release -f netcoreapp3.1 -r win7-x64 -o SvgToPng_netcoreapp3.1_win7-x64
cd ./src/SvgToPng
dotnet publish -c Release -f net461 -r win7-x64 -o SvgToPng_net461_win7-x64
cd ./src/SvgXml.Diagnostics
dotnet publish -c Release -f netcoreapp3.1 -r win7-x64 -o SvgXml.Diagnostics_netcoreapp3.1_win7-x64
cd ./src/Svg.Skia.Converter
dotnet publish -c Release -f netcoreapp3.1 -r win-x64 -o Svg.Skia.Converter_netcoreapp3.1_win-x64
cd ./src/Svg.Skia.Converter
dotnet publish -c Release -f netcoreapp3.1 -r linux-x64 -o Svg.Skia.Converter_netcoreapp3.1_linux-x64
cd ./src/Svg.Skia.Converter
dotnet publish -c Release -f netcoreapp3.1 -r osx-x64 -o Svg.Skia.Converter_netcoreapp3.1_osx-x64
The Svg.Skia
library is using code from the https://github.com/vvvv/SVG
Parts of Svg.Skia source code are adapted from the https://github.com/vvvv/SVG
Svg.Skia is licensed under the MIT license.