QR Code Generator in C# (.NET): The Powerful QRCoder Tool
QR codes have become an integral part of the modern web and mobile applications. They are used for quick link navigation, transferring contact data, authentication, payments, and much more. If you are developing an application on the .NET (C#) platform, one of the best solutions for generating QR codes is the QRCoder library. It is a lightweight, high-performance, fully managed open-source library that requires no external dependencies (such as ImageMagick or ZXing).
What is QRCoder?
QRCoder is a pure C# implementation of the QR code standard (ISO/IEC 18004). It allows you to create QR codes of various versions (from 1 to 40), set the error correction level (L, M, Q, H), embed logos, and export the result in PNG, BMP, JPG, GIF formats, as well as SVG or XAML (via additional modules). The library works with both .NET Framework (starting from 4.6) and .NET Core / .NET 5/6/7/8, making it a universal choice for web applications (ASP.NET), desktop (WPF, WinForms), and console projects.
Installation and Setup
Installing QRCoder is done via the NuGet package manager. Execute one of the following commands:
// Via Package Manager ConsoleInstall-Package QRCoder
// Via .NET CLIdotnet add package QRCoderAfter installing the library, you can immediately start generating QR codes. No additional configuration is required.
Basic Example: Generating a QR Code with Text
The simplest way is to create a QR code containing an arbitrary string (URL, text, phone number). The example below generates a QR code and saves it to a file:
using QRCoder;using System.Drawing;using System.Drawing.Imaging;
class Program{ static void Main() { // 1. Create the generator QRCodeGenerator qrGenerator = new QRCodeGenerator();
// 2. Create QR code data (text, error correction level) QRCodeData qrCodeData = qrGenerator.CreateQrCode( "https://pythonlib.ru", QRCodeGenerator.ECCLevel.Q // Level Q — 25% recovery );
// 3. Create the graphical representation QRCode qrCode = new QRCode(qrCodeData);
// 4. Render to Bitmap (module size 20 pixels) Bitmap qrCodeImage = qrCode.GetGraphic(20);
// 5. Save to file qrCodeImage.Save("qrcode.png", ImageFormat.Png);
Console.WriteLine("QR code created: qrcode.png"); }}As a result, you will get a qrcode.png file with a black-and-white QR code. The Q error correction level allows recovering up to 25% of damaged data — optimal for most tasks.
QR Code with Logo (Branding)
QRCoder supports embedding an image in the center of the QR code. This is useful for branded stickers or business cards. Important: the logo should not cover more than 30% of the code area, otherwise scanning will become impossible.
using QRCoder;using System.Drawing;
public Bitmap GenerateQrWithLogo(string text, string logoPath){ QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData);
// Load the logo Image logo = Image.FromFile(logoPath);
// Generate with logo (module size 20, background color white, logo centered) Bitmap result = qrCode.GetGraphic(20, Color.Black, Color.White, logo); return result;}Customizing Appearance: Color and Size
You can easily change the colors of the QR code to adapt it to your application's design. The GetGraphic method accepts parameters:
- pixelsPerModule — the size of one