Skip to content
English
  • There are no suggestions because the search field is empty.

Can IronQR Save QR Codes in SVG Format?

Short Answer: Not Natively — But There’s a Workaround

 

A common question developers ask when working with IronQR, the QR code generation library from Iron Software, is:

“Can I save the generated QR code as an SVG?”

As of now, IronQR does not support exporting QR codes directly in SVG format.


Why Not?

IronQR relies on the SixLabors.ImageSharp library for image processing. While powerful and flexible for raster formats (like PNG, JPEG, BMP, etc.), ImageSharp does not support SVG as an output format. This is a known limitation of the library it depends on.


The Workaround: Use Svg.NET to Redraw as SVG

While direct SVG export is not built-in, developers can convert or recreate the QR code as an SVG using a third-party library like Svg.NET.

Here’s how you can approach it:

  1. Generate the QR code matrix/data using IronQR.

  2. Use Svg.NET to recreate that matrix into an SVG path or rectangles.

This allows you to maintain full control over the styling and structure of the final SVG file while leveraging IronQR’s easy QR code generation.


Example Approach

While implementation details vary depending on your project, here's a simplified breakdown:

var qr = QrWriter.Write("Hello SVG");
var anyBitmap = qr.Save();

// Step 2: Convert AnyBitmap to System.Drawing.Bitmap
System.Drawing.Bitmap bit = anyBitmap;

// Step 3: Create new SVG document
var svgDoc = new SvgDocument
{
    Width = bit.Width,
    Height = bit.Height
};

// Step 4: 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);
        }
    }
}

// Step 5: Save the result as SVG
svgDoc.Write("qr-from-ironqr.svg");

Summary

  • IronQR does not support SVG output directly due to the limitations of ImageSharp.

  • You can redraw the QR code as an SVG using tools like Svg.NET.

  • This is a viable solution for developers who need scalable, vector-based QR codes for printing or high-resolution usage.