Saving QR Codes as SVG in IronQR

IronQR does not export QR codes directly to SVG. You can still produce a vector file by redrawing the generated bitmap as SVG rectangles with a third-party library.

The reason is the underlying image stack. IronQR uses SixLabors.ImageSharp for image processing, which handles raster formats such as PNG, JPEG, and BMP but offers no SVG output. SVG simply is not a target format the dependency supports.

Solution

Generate the QR code with IronQR as usual, then walk its pixels and rebuild the matrix as vector shapes using Svg.NET. You keep IronQR's QR generation and gain full control over the SVG's styling and structure.

1. Generate the QR Code and Convert to a Bitmap

Write the QR code, save it to an AnyBitmap, then cast that to a System.Drawing.Bitmap so the pixels can be read individually.

var qr = QrWriter.Write("Hello SVG");
var anyBitmap = qr.Save();
// Convert AnyBitmap to System.Drawing.Bitmap
System.Drawing.Bitmap bit = anyBitmap;
var qr = QrWriter.Write("Hello SVG");
var anyBitmap = qr.Save();
// Convert AnyBitmap to System.Drawing.Bitmap
System.Drawing.Bitmap bit = anyBitmap;
Dim qr = QrWriter.Write("Hello SVG")
Dim anyBitmap = qr.Save()
' Convert AnyBitmap to System.Drawing.Bitmap
Dim bit As System.Drawing.Bitmap = anyBitmap
$vbLabelText   $csharpLabel

2. Redraw the Pixels as SVG Rectangles

Create an SvgDocument sized to the bitmap, then loop the pixels and add a 1x1 SvgRectangle wherever a pixel reads as black. The threshold check (R, G, and B all below 128) treats near-black pixels as filled cells.

// Create new SVG document
var svgDoc = new SvgDocument
{
    Width = bit.Width,
    Height = bit.Height
};
// Loop through bitmap pixels and add black pixels as SVG rectangles
for (int y = 0; y < bit.Height; y++)
{
    for (int x = 0; x < bit.Width; x++)
    {
        System.Drawing.Color pixel = bit.GetPixel(x, y);
        // Check if pixel is black (or close enough)
        if (pixel.R < 128 && pixel.G < 128 && pixel.B < 128)
        {
            var rect = new SvgRectangle
            {
                X = x,
                Y = y,
                Width = 1,
                Height = 1,
                Fill = new SvgColourServer(System.Drawing.Color.Black)
            };
            svgDoc.Children.Add(rect);
        }
    }
}
// Create new SVG document
var svgDoc = new SvgDocument
{
    Width = bit.Width,
    Height = bit.Height
};
// Loop through bitmap pixels and add black pixels as SVG rectangles
for (int y = 0; y < bit.Height; y++)
{
    for (int x = 0; x < bit.Width; x++)
    {
        System.Drawing.Color pixel = bit.GetPixel(x, y);
        // Check if pixel is black (or close enough)
        if (pixel.R < 128 && pixel.G < 128 && pixel.B < 128)
        {
            var rect = new SvgRectangle
            {
                X = x,
                Y = y,
                Width = 1,
                Height = 1,
                Fill = new SvgColourServer(System.Drawing.Color.Black)
            };
            svgDoc.Children.Add(rect);
        }
    }
}
Imports System.Drawing

' Create new SVG document
Dim svgDoc As New SvgDocument With {
    .Width = bit.Width,
    .Height = bit.Height
}

' Loop through bitmap pixels and add black pixels as SVG rectangles
For y As Integer = 0 To bit.Height - 1
    For x As Integer = 0 To bit.Width - 1
        Dim pixel As Color = bit.GetPixel(x, y)
        ' Check if pixel is black (or close enough)
        If pixel.R < 128 AndAlso pixel.G < 128 AndAlso pixel.B < 128 Then
            Dim rect As New SvgRectangle With {
                .X = x,
                .Y = y,
                .Width = 1,
                .Height = 1,
                .Fill = New SvgColourServer(Color.Black)
            }
            svgDoc.Children.Add(rect)
        End If
    Next
Next
$vbLabelText   $csharpLabel

3. Write the SVG File

Save the document to disk once every black cell has been added.

// Save the result as SVG
svgDoc.Write("qr-from-ironqr.svg");
// Save the result as SVG
svgDoc.Write("qr-from-ironqr.svg");
' Save the result as SVG
svgDoc.Write("qr-from-ironqr.svg")
$vbLabelText   $csharpLabel

This gives you a scalable, vector-based QR code suitable for print or high-resolution use.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 69,438 | Version: 2026.7 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronQR
run a sample watch your URL become a QR code.