I'm trying to use SkiaSharp to convert an SVG file to PNG. I know there are many alternatives, but I wanted to evaluate it's SVG load support.
Is this possible? I tried this:
var svg = new SKSvg(new SKSize(200, 200));
svg.Load("image.svg");
var bitmap = new SKBitmap((int)svg.CanvasSize.Width, (int)svg.CanvasSize.Height);
var canvas = new SKCanvas(bitmap);
canvas.DrawPicture(svg.Picture);
canvas.Flush();
canvas.Save();
using (var image = SKImage.FromBitmap(bitmap))
using (var data = image.Encode(SKImageEncodeFormat.Png, 80))
{
// save the data to a stream
using (var stream = File.OpenWrite("image.png"))
{
data.SaveTo(stream);
}
}
But I just get an empty image.
svg.CanvasSize.Width
andsvg.CanvasSize.Height
– Auberbach