C# QR Code Library

Generate QR Codes with C#

C# developers can use QRCoder, a popular .NET library, to generate QR codes in ASP.NET, WPF, MAUI, and console applications. No external dependencies required.

Installation

Install QRCoder via NuGet Package Manager.

NuGet
dotnet add package QRCoder
Package Manager
Install-Package QRCoder

Generate QR Codes with QRCoder

Code examples using the QRCoder library in C#.

Basic QR Code with QRCoder

using QRCoder;

var qrGenerator = new QRCodeGenerator();
var qrData = qrGenerator.CreateQrCode("https://qrcode.fun",
    QRCodeGenerator.ECCLevel.Q);

// PNG output
var qrCode = new PngByteQRCode(qrData);
byte[] pngBytes = qrCode.GetGraphic(20);
File.WriteAllBytes("qrcode.png", pngBytes);

SVG Output

using QRCoder;

var qrGenerator = new QRCodeGenerator();
var qrData = qrGenerator.CreateQrCode("https://qrcode.fun",
    QRCodeGenerator.ECCLevel.Q);

var svgQrCode = new SvgQRCode(qrData);
string svgString = svgQrCode.GetGraphic(20,
    "#1A2B3C", "#FFFFFF");
File.WriteAllText("qrcode.svg", svgString);

ASP.NET Core Endpoint

app.MapGet("/qr", (string data) =>
{
    var qrGenerator = new QRCodeGenerator();
    var qrData = qrGenerator.CreateQrCode(data,
        QRCodeGenerator.ECCLevel.Q);
    var qrCode = new PngByteQRCode(qrData);
    byte[] png = qrCode.GetGraphic(20);

    return Results.File(png, "image/png");
});
QRCode.fun API

Generate QR Codes via API in C#

Call the QRCode.fun API from C# using HttpClient for styled QR codes.

C# API Integration
using System.Net.Http.Json;

var client = new HttpClient();
var payload = new {
    data = "https://qrcode.fun",
    width = 300,
    height = 300,
    type = "png",
    margin = 10,
    dotsOptions = new { color = "#1A2B3C", type = "rounded" },
    cornersSquareOptions = new { color = "#8564C3", type = "extra-rounded" },
    backgroundOptions = new { color = "#FFFFFF" }
};

var response = await client.PostAsJsonAsync(
    "https://qrcode.fun/api/generate-qr-styled", payload);
var result = await response.Content.ReadFromJsonAsync<JsonElement>();
Console.WriteLine(result.GetProperty("data").GetString()?[..50]);

Live QR Code Preview

Try generating a QR code with C# right now.

QR preview

Native Library vs API

Compare using QRCoder versus the QRCode.fun API.

FeatureQRCoderQRCode.fun API
Setup complexityNuGet installSingle HTTP request via HttpClient
CustomizationColors, logos, shapes (ArtQRCode)Full styling: colors, shapes, logos
Offline supportYesRequires internet
MaintenanceNuGet updateAlways up-to-date
Output formatsPNG, SVG, PDF, ASCIIPNG, SVG

C# QR Code Use Cases

Common scenarios for QR codes in .NET applications.

ASP.NET Web APIs

Generate QR codes in ASP.NET Core APIs for tickets, invoices, authentication tokens, and product pages.

WPF & MAUI Desktop Apps

Create desktop applications with QR code generation for labels, business cards, and asset tracking.

Azure Functions

Deploy QR generation as serverless Azure Functions triggered by HTTP requests or queue messages.

Reporting & PDF

Embed QR codes into PDF reports and documents using QuestPDF or iTextSharp for payment and tracking.

C# QR Code Ecosystem Deep Dive

The .NET ecosystem provides enterprise-grade QR code generation across web, desktop, mobile, and cloud platforms.

ASP.NET Core Middleware & Dependency Injection

Register QRCoder as a scoped service in ASP.NET Core's DI container for clean separation of concerns. Create a dedicated QR middleware that intercepts specific routes and returns QR images. Use IMemoryCache or IDistributedCache (Redis) to cache generated QR codes by content hash, avoiding redundant generation. In minimal APIs (.NET 7+), return Results.Bytes(pngData, "image/png") for lightweight QR endpoints.

MAUI & Cross-Platform Desktop Apps

.NET MAUI enables QR code generation across Windows, macOS, Android, and iOS from a single codebase. QRCoder works on all MAUI platforms for local generation. Create a QrCodeView custom control that wraps QRCoder's SVG output in a WebView or renders PNG to an Image control. For WPF legacy apps, QRCoder's BitmapByteQRCode generates byte arrays that convert directly to BitmapImage sources.

Azure Functions & Serverless Deployment

Deploy QR generation as Azure Functions for auto-scaling, pay-per-execution pricing. Use HTTP-triggered functions that accept QR parameters and return PNG responses. For batch scenarios, use Queue-triggered functions that process QR generation requests from Azure Service Bus. QRCoder's lightweight footprint ensures cold starts under 500ms. Combine with Azure CDN to cache frequently-requested QR codes at the edge.

Frequently Asked Questions

Common questions about generating QR codes with C#.

QRCoder is an open-source .NET library for generating QR codes. It supports multiple output formats including PNG, SVG, PDF, and ASCII art, with no external dependencies.

Explore QR Code Libraries for Other Languages

Find QR code generation guides and code examples for your preferred programming language.

Start generating QR codes with C#

Use our free generator or integrate the API into your .NET applications.