SVG-to-PNG in .NET is surprisingly tricky because SVG rendering requires a browser-grade engine for complex files. Svg.Skia uses SkiaSharp — the same rendering engine used in Xamarin, MAUI, and Chrome — so complex SVGs with gradients, filters, and masks render correctly. ImageSharp's SVG support is more limited. The ChangeThisFile API uses a headless browser for maximum fidelity.

Method 1: Svg.Skia (SkiaSharp renderer, best SVG support)

Svg.Skia renders SVGs to SkiaSharp bitmaps. Best support for gradients, filters, masks, and complex paths. MIT license.

dotnet add package Svg.Skia
dotnet add package SkiaSharp
using Svg.Skia;
using SkiaSharp;

public static class SvgToPng
{
    /// <summary>Converts an SVG file to PNG at the specified scale factor.</summary>
    /// <param name="scale">2.0 = 2x resolution (Retina). 1.0 = 1:1 with SVG viewBox.</param>
    public static void Convert(
        string svgPath,
        string pngPath,
        float scale = 1.0f,
        bool transparentBackground = true)
    {
        using var svg = new SKSvg();
        svg.Load(svgPath);

        if (svg.Picture == null)
            throw new InvalidOperationException($"Failed to parse SVG: {svgPath}");

        var bounds = svg.Picture.CullRect;
        int width = (int)(bounds.Width * scale);
        int height = (int)(bounds.Height * scale);

        var info = new SKImageInfo(
            width, height,
            SKColorType.Rgba8888, SKAlphaType.Premul);

        using var surface = SKSurface.Create(info);
        var canvas = surface.Canvas;

        if (!transparentBackground)
            canvas.Clear(SKColors.White);
        else
            canvas.Clear(SKColors.Transparent);

        canvas.Scale(scale);
        canvas.DrawPicture(svg.Picture);
        canvas.Flush();

        using var image = surface.Snapshot();
        using var data = image.Encode(SKEncodedImageFormat.Png, 100);
        File.WriteAllBytes(pngPath, data.ToArray());
    }
}

// Usage — 2x scale for Retina/HiDPI exports
SvgToPng.Convert("logo.svg", "logo@2x.png", scale: 2.0f);

// Fixed pixel size (compute scale from desired width)
// var scale = targetWidth / svgNativeWidth;
SvgToPng.Convert("icon.svg", "icon-128.png", scale: 128f / 24f);

Method 2: SixLabors.ImageSharp with SVG extension

ImageSharp processes SVGs through its DrawingContext extension. Pure .NET managed code — no SkiaSharp native libs needed.

dotnet add package SixLabors.ImageSharp
dotnet add package SixLabors.ImageSharp.Drawing
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using System.Xml;

// Note: ImageSharp does not natively parse and render full SVG files.
// For basic SVG rasterization in pure .NET, use Svg.Skia (Method 1).
// ImageSharp is the right choice for post-processing the PNG output:

public static class PngProcessor
{
    /// <summary>
    /// Example: resize a PNG output from Svg.Skia.
    /// ImageSharp is ideal for the resize/crop/encode step after rasterization.
    /// </summary>
    public static async Task ResizeAsync(
        string pngPath,
        string outputPath,
        int targetWidth,
        CancellationToken ct = default)
    {
        using var image = await Image.LoadAsync(pngPath, ct);
        image.Mutate(ctx => ctx.Resize(new ResizeOptions
        {
            Size = new Size(targetWidth, 0), // 0 = auto height
            Mode = ResizeMode.Max
        }));
        await image.SaveAsPngAsync(outputPath, ct);
    }
}

ImageSharp doesn't include a full SVG renderer. Use Svg.Skia for the rasterization step, then chain ImageSharp for resizing, cropping, or format conversion. This two-library pattern covers all SVG export needs without PuppeteerSharp.

Method 3: ChangeThisFile API (HttpClient, headless browser rendering)

The API renders SVGs with a headless browser — maximum fidelity including CSS animations (first frame), web fonts, and complex filters. Free tier: 1,000 conversions/month.

# Verify with curl first
curl -X POST https://changethisfile.com/v1/convert \
  -H "Authorization: Bearer ctf_sk_your_key" \
  -F "file=@logo.svg" \
  -F "target=png" \
  --output logo.png
using System.Net.Http;
using System.Net.Http.Headers;

public class SvgConvertService
{
    private readonly HttpClient _http;
    private const string ApiKey = "ctf_sk_your_key_here";

    public SvgConvertService(IHttpClientFactory factory)
        => _http = factory.CreateClient("ctf");

    public async Task ConvertAsync(
        string svgPath,
        string pngPath,
        CancellationToken ct = default)
    {
        await using var fileStream = File.OpenRead(svgPath);
        using var form = new MultipartFormDataContent();

        var fileContent = new StreamContent(fileStream);
        fileContent.Headers.ContentType =
            new MediaTypeHeaderValue("image/svg+xml");
        form.Add(fileContent, "file", Path.GetFileName(svgPath));
        form.Add(new StringContent("png"), "target");

        using var request = new HttpRequestMessage(HttpMethod.Post, "/v1/convert")
        {
            Content = form,
            Headers = { Authorization =
                new AuthenticationHeaderValue("Bearer", ApiKey) }
        };

        using var response = await _http.SendAsync(request, ct);
        response.EnsureSuccessStatusCode();

        await using var outStream = File.Create(pngPath);
        await response.Content.CopyToAsync(outStream, ct);
    }
}

When to use each

ApproachBest forTradeoff
Svg.SkiaFull SVG 1.1 support, scale to any DPI, transparent backgroundsSkiaSharp native libs; larger container image
ImageSharp (post-process)Resize/crop/encode PNG after Svg.Skia rasterizes itDoes not render SVG directly — chain with Svg.Skia
ChangeThisFile APIComplex SVGs with web fonts or CSS, no native rendering depsNetwork call; 25MB file limit on free tier

Production tips

  • Use a scale factor, not fixed pixel dimensions. SVGs are vector — scale: 2.0 gives you Retina quality at double the viewBox resolution. Compute the scale from your target pixel width: scale = targetWidth / svgViewBoxWidth.
  • Check svg.Picture != null after loading. Svg.Skia returns null for malformed SVGs. Validate before calling DrawPicture or you'll get a null reference exception.
  • Use IHttpClientFactory for the API. Register a named client in Program.cs with a 30-second timeout and inject IHttpClientFactory into your service.
  • Pass CancellationToken throughout. Wire it from HttpContext.RequestAborted in ASP.NET controllers.
  • Transparent backgrounds are the safe default. For SVG icons and logos, transparent PNG is almost always what you want. Only use a white background when the output will be embedded in a context that can't handle transparency.

Svg.Skia is the right default for SVG-to-PNG in .NET — SkiaSharp rendering matches what browsers produce for most SVG 1.1 content. Chain ImageSharp after rasterization for resize and format work. The ChangeThisFile API handles edge cases (CSS animations, web fonts) without any local rendering engine. Free tier: 1,000 conversions/month.