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.
dotnet add package QRCoderInstall-Package QRCoderGenerate QR Codes with QRCoder
Code examples using the QRCoder library in C#.
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);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);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");
});Generate QR Codes via API in C#
Call the QRCode.fun API from C# using HttpClient for styled QR codes.
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.
Native Library vs API
Compare using QRCoder versus the QRCode.fun API.
| Feature | QRCoder | QRCode.fun API |
|---|---|---|
| Setup complexity | NuGet install | Single HTTP request via HttpClient |
| Customization | Colors, logos, shapes (ArtQRCode) | Full styling: colors, shapes, logos |
| Offline support | Yes | Requires internet |
| Maintenance | NuGet update | Always up-to-date |
| Output formats | PNG, SVG, PDF, ASCII | PNG, 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.
Frequently Asked Questions
Common questions about generating QR codes with C#.
Start generating QR codes with C#
Use our free generator or integrate the API into your .NET applications.