Skip to content

scherven/QRCoder

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

QRCoder

License NuGet Nuget Coverage GitHub contributors

QRCoder is a simple C# library originally created by Raffael Herrmann for generating QR codes and Micro QR codes.

โœจ Features

  • ๐Ÿš€ Zero dependencies - No external libraries required (framework dependencies only)
  • โšก Fast performance - Optimized QR code generation with low memory footprint
  • ๐ŸŽจ Multiple output formats - PNG, SVG, PDF, ASCII, Bitmap, PostScript, and more
  • ๐Ÿ“ฑ 23+ payload generators - WiFi, vCard, URLs, payments, and many more
  • ๐Ÿ”ง Highly configurable - Error correction levels, custom colors, logos, and styling
  • ๐ŸŒ Cross-platform - Supports .NET 5+, .NET Framework 3.5+, .NET Core 1.0+, and .NET Standard 1.3+
  • ๐Ÿ“ฆ Micro QR codes - Smaller QR codes for space-constrained applications

๐Ÿ“ฆ Installation

Install via NuGet Package Manager:

PM> Install-Package QRCoder

๐Ÿš€ Quick Start

Generate a QR code with just a few lines of code, either using a renderer's static helper method, or by creating a QR code first and then passing it to a renderer:

using QRCoder;

// Generate a simple black and white PNG QR code
byte[] qrCodeImage = PngByteQRCodeHelper.GetQRCode("Hello World", QRCodeGenerator.ECCLevel.Q, 20);

// Generate a scalable black and white SVG QR code
using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q);
using var svgRenderer = new SvgQRCode(qrCodeData);
string svg = svgRenderer.GetGraphic();

For more examples and detailed usage instructions, see: Wiki: How to use QRCoder

๐Ÿ“ฑ Payload Generators

QR codes can encode structured data that triggers specific actions when scanned (e.g., WiFi credentials, contact information, URLs). QRCoder includes payload generators that create properly formatted strings for these common use cases.

Usage Example

using QRCoder;

// Create a bookmark payload
var bookmarkPayload = new PayloadGenerator.Bookmark("https://github.com/Shane32/QRCoder", "QRCoder Repository");

// Generate the QR code data from the payload
using var qrCodeData = QRCodeGenerator.GenerateQrCode(bookmarkPayload);

// Or override the ECC level
using var qrCodeData2 = QRCodeGenerator.GenerateQrCode(bookmarkPayload, QRCodeGenerator.ECCLevel.H);

// Render the QR code
using var pngRenderer = new PngByteQRCode(qrCodeData);
byte[] qrCodeImage = pngRenderer.GetGraphic(20);

Available Payload Types

Payload Type Usage Example Description
WiFi new PayloadGenerator.WiFi(ssid, password, auth) WiFi network credentials
URL new PayloadGenerator.Url("https://example.com") Website URL
Bookmark new PayloadGenerator.Bookmark(url, title) Browser bookmark
Mail new PayloadGenerator.Mail(email, subject, body) Email with pre-filled fields
SMS new PayloadGenerator.SMS(number, message) SMS message
MMS new PayloadGenerator.MMS(number, subject) MMS message
Geolocation new PayloadGenerator.Geolocation(lat, lng) GPS coordinates
PhoneNumber new PayloadGenerator.PhoneNumber(number) Phone number for calling
SkypeCall new PayloadGenerator.SkypeCall(username) Skype call
WhatsAppMessage new PayloadGenerator.WhatsAppMessage(number, msg) WhatsApp message
ContactData new PayloadGenerator.ContactData(...) vCard/MeCard contact
CalendarEvent new PayloadGenerator.CalendarEvent(...) iCal/vEvent
OneTimePassword new PayloadGenerator.OneTimePassword(...) TOTP/HOTP for 2FA
BitcoinAddress new PayloadGenerator.BitcoinAddress(address) Bitcoin payment
BitcoinCashAddress new PayloadGenerator.BitcoinCashAddress(address) Bitcoin Cash payment
LitecoinAddress new PayloadGenerator.LitecoinAddress(address) Litecoin payment
MoneroTransaction new PayloadGenerator.MoneroTransaction(...) Monero payment
SwissQrCode new PayloadGenerator.SwissQrCode(...) Swiss QR bill (ISO-20022)
Girocode new PayloadGenerator.Girocode(...) SEPA payment (EPC QR)
BezahlCode new PayloadGenerator.BezahlCode(...) German payment code
RussiaPaymentOrder new PayloadGenerator.RussiaPaymentOrder(...) Russian payment (ะ“ะžะกะข ะ  56042-2014)
SlovenianUpnQr new PayloadGenerator.SlovenianUpnQr(...) Slovenian UPN payment
ShadowSocksConfig new PayloadGenerator.ShadowSocksConfig(...) Shadowsocks proxy config

For detailed information about payload generators, see: Wiki: Advanced usage - Payload generators

๐ŸŽจ QR Code Renderers

QRCoder provides multiple renderers for different output formats and use cases. Each renderer has specific capabilities and framework requirements.

Renderer Output Format Requires Usage Example
PngByteQRCode PNG byte array โ€” new PngByteQRCode(data).GetGraphic(20)
SvgQRCode SVG string โ€” new SvgQRCode(data).GetGraphic(20)
QRCode System.Drawing.Bitmap Windowsยน new QRCode(data).GetGraphic(20)
ArtQRCode Artistic bitmap with custom images Windowsยน new ArtQRCode(data).GetGraphic(20)
AsciiQRCode ASCII art string โ€” new AsciiQRCode(data).GetGraphic(1) or new AsciiQRCode(data).GetGraphicSmall()
Base64QRCode Base64 encoded image โ€” new Base64QRCode(data).GetGraphic(20)
BitmapByteQRCode BMP byte array โ€” new BitmapByteQRCode(data).GetGraphic(20)
PdfByteQRCode PDF byte array โ€” new PdfByteQRCode(data).GetGraphic(20)
PostscriptQRCode PostScript/EPS string โ€” new PostscriptQRCode(data).GetGraphic(20)
XamlQRCode XAML DrawingImage XAMLยฒ new XamlQRCode(data).GetGraphic(20)
UnityQRCode Unity Texture2D Unityยณ new UnityQRCode(data).GetGraphic(20)

Notes:

  • ยน Requires Windows or System.Drawing.Common package (uses GDI+)
  • ยฒ Requires the QRCoder.Xaml package
  • ยณ Requires the QRCoder.Unity package

Framework Compatibility: Not all renderers are available on all target frameworks. Check the compatibility table for details.

For comprehensive information about renderers, see: Wiki: Advanced usage - QR Code renderers

๐Ÿ”ง Advanced Features

Micro QR Codes

QRCoder supports Micro QR codes, which are smaller versions of standard QR codes suitable for applications with limited space. Micro QR codes have significantly limited storage capacityโ€”as few as 5 numeric digits (M1) or as many as 35 numeric digits (M4), with alphanumeric and byte data storing considerably less.

using QRCoder;

// Generate a Micro QR code (versions M1-M4, represented as -1 to -4)
using var qrCodeData = QRCodeGenerator.GenerateMicroQrCode("Hello", QRCodeGenerator.ECCLevel.L, requestedVersion: -2);
using var qrCode = new PngByteQRCode(qrCodeData);
byte[] qrCodeImage = qrCode.GetGraphic(20);

Note: Micro QR codes have limitations on data capacity and error correction levels. They support versions M1 through M4 (specified as -1 to -4), and not all ECC levels are available for all versions. M1 only supports detection (no ECC), M2 and M3 support L and M levels, and M4 supports L, M, and Q levels. For detailed capacity tables, see the Micro QR Code specification.

Working with QRCodeData

QRCodeData is the core data structure that represents a QR code's module matrix. It contains a List<BitArray> called ModuleMatrix, where each BitArray represents a row of modules in the QR code. A module is set to true for dark/black modules and false for light/white modules.

You can access the ModuleMatrix directly to read or manipulate the QR code data at the module level. This is useful for custom rendering implementations or analyzing QR code structure.

using QRCoder;

// Generate QR code data
using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q);

// Access the module matrix
var moduleMatrix = qrCodeData.ModuleMatrix;
int size = moduleMatrix.Count; // Size of the QR code (includes quiet zone)

// Manually render as ASCII (versus the included ASCII renderer)
for (int y = 0; y < size; y++)
{
    for (int x = 0; x < size; x++)
    {
        // Check if module is dark (true) or light (false)
        bool isDark = moduleMatrix[y][x];
        Console.Write(isDark ? "โ–ˆโ–ˆ" : "  ");
    }
    Console.WriteLine();
}

โš ๏ธ Troubleshooting

System.Drawing.Common Warnings (QRCode and ArtQRCode renderers)

The QRCode and ArtQRCode renderers depend on System.Drawing.Common, which Microsoft has removed cross-platform support for in .NET 6+. You may encounter one of the following build or runtime errors:

CA1416: This call site is reachable on all platforms. 'QRCode.QRCode(QRCodeData)' is only supported on: 'windows'

System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.

System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.

Solutions include:

  1. Use Windows-specific TFMs such as <TargetFramework>net8.0-windows</TargetFramework>
  2. Mark methods with the [SupportedOSPlatform("windows")] attribute
  3. Add platform guards by wrapping code with #if WINDOWS or if (OperatingSystem.IsWindows())
  4. Use cross-platform renderers such as PngByteQRCode, SvgQRCode, or BitmapByteQRCode

๐Ÿš€ CI Builds

The NuGet feed contains only major/stable releases. If you want the latest functions and features, you can use the CI builds via Github packages.

(More information on how to use Github Packages in Nuget Package Manager can be found here.)

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

๐Ÿ“„ License

QRCoder is a project originally by Raffael Herrmann and was first released in 10/2013. It's licensed under the MIT license.

Since 2025, QRCoder has been maintained by Shane32 with contributions from the community.

๐Ÿ™ Credits

Glory to Jehovah, Lord of Lords and King of Kings, creator of Heaven and Earth, who through his Son Jesus Christ, has redeemed me to become a child of God. -Shane32

About

A pure C# Open Source QR Code implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.7%
  • PostScript 0.3%