Developer Documentation
C#
Updated September 19, 2026

Generate QR Codes in C#

Generate QR codes for text or URLs and export them as images in C#.

QR code libraries handle matrix construction, masking, and error correction for you. Your application still needs to choose suitable error correction, margin, image size, and payload encoding.

Quick Start#

The following example uses the standard C# API or a widely used package for this task.

Using QRCoder#

C#
1// dotnet add package QRCoder2using QRCoder;34using var generator = new QRCodeGenerator();5using QRCodeData data = generator.CreateQrCode(6    "https://toolporta.com",7    QRCodeGenerator.ECCLevel.M8);9using var png = new PngByteQRCode(data);10byte[] bytes = png.GetGraphic();11await File.WriteAllBytesAsync("toolporta.png", bytes);

Common Operations#

This second pattern covers a common production operation or a safer way to handle real input.

Higher error correction#

C#
1using QRCodeData data = generator.CreateQrCode(2    payload,3    QRCodeGenerator.ECCLevel.Q4);

Important Notes#

Do not treat a successfully generated image as proof it will scan. Contrast, physical size, damage, payload density, and logos all affect reliability.

Best Practices#

  1. Treat external input as untrusted and handle parse/validation errors explicitly.
  2. Keep encoding, units, formats, and library-specific mapping rules explicit at system boundaries.
  3. Add test vectors that cover empty input, Unicode text, malformed input, and representative production data.

References#

Implement QR Code in other languages: