Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog

Create QR Codes with .NET

Create QR Codes with .NET
December 5, 2023 3 min read BEN ABT
.NET Csharp

This article was written in 2023. Versions, tools and recommendations may have changed since then. Newer posts are collected under .NET.

QR codes are a simple and very popular way of exchanging data and information - even in .NET. They have become part of everyday life.

Unfortunately, .NET does not natively support the generation of QRCodes; we have to rely on the community. Fortunately, there is a very good library that we can use: QRCoder by Raffael Herrmann .

Install QRCoder

The installation is simple. We can install the library via NuGet:

Shell
dotnet add package QRCoder

Using QRCoder

The structure and use of the library is very simple: we basically just need to create an instance of the QRCodeGenerator class and call the CreateQrCode method. The CreateQrCode method returns a QRCodeData object, which we can then convert into a Bitmap object.

A more realistic example is that we abstract the generation of the QRCode into a provider, which allows us to separate the implementation from the use and also to implement unit tests more easily.

C#
 1// Defining the QRCodeProvider class
 2// Add an interface to your code!
 3public class QRCodeProvider
 4{
 5    // Creating a new instance of QRCodeGenerator
 6    // In principle, this class supports IDisposable, but we can re-use this instance
 7    private static readonly QRCodeGenerator s_qrGenerator = new();
 8
 9    // Method to generate the QR code
10    public byte[] GeneratePng(string text)
11    {
12        // Creating the QR code data with our defaults
13        using QRCodeData qrCodeData = s_qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.Q);
14
15        // Creating a new instance of PngByteQRCode with the QR code data
16        // We can also use other Image types, like BitmapByteQRCode
17        PngByteQRCode qrCode = new (qrCodeData);
18
19        // Returning the QR code as a graphic
20        return qrCode.GetGraphic(pixelsPerModule: 20);
21    }
22}

The QRCodeProvider class can now either be used directly or integrated cleanly into a dependency injection container with an additional interface.

By calling the provider, we can generate our QRCode as a PNG with a handful of code - in this example stored on the file system.

C#
 1// NuGet: https://github.com/codebude/QRCoder
 2using QRCoder;
 3
 4namespace BenjaminAbt_Samples_QrCode // Defining the namespace
 5{
 6    internal class Program // Defining the Program class
 7    {
 8        static void Main(string[] args)
 9        {
10            // Creating a new instance of QRCodeProvider
11            // This is our own abstraction
12            QRCodeProvider qrCodeProvider = new();
13
14            // Defining the path where the QR code will be saved
15            // You can use different types of images and also svg or In-Memory
16            string path = @"C:\temp\qrcodetest.png";
17
18            string sampleText = "Hello World";
19
20            // Generating the QR code
21            byte[] png = qrCodeProvider.GeneratePng(sampleText);
22
23            File.WriteAllBytes(path, png); // Writing the QR code to the file
24        }
25    }
26
27    // QRCodeProvider here
28}

Related articles

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026 - 11 min read

Containerizing .NET in 2026 Without a Dockerfile

Most .NET Dockerfiles repeat the same five steps: restore, publish, select the matching Microsoft runtime image, copy the output and start …

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026 - 12 min read

Problem Details in ASP.NET Core and .NET 11

builder.Services.AddProblemDetails() registers infrastructure. It does not create an error contract. An ASP.NET Core request can fail during …

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026 - 11 min read

Resilience in .NET with Microsoft.Extensions.Resilience

Retries are the most visible resilience strategy and the easiest one to misuse. Repeating a failing call can recover from a short network …


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
Stop Using nginx as Your Default Static File Server in Docker

Stop Using nginx as Your Default Static File Server in …

Oct 24, 2026
Containerizing .NET in 2026 Without a Dockerfile

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026
Problem Details in ASP.NET Core and .NET 11

Problem Details in ASP.NET Core and .NET 11

Oct 5, 2026
Resilience in .NET with Microsoft.Extensions.Resilience

Resilience in .NET with Microsoft.Extensions.Resilience

Sep 21, 2026
What Matters in ASP.NET Core 11

What Matters in ASP.NET Core 11

Sep 14, 2026

Tags

.NET (192) Csharp (96) ASP.NET Core (48) Azure (41) DevOps (17) Docker (14) Microsoft (14) EF Core (11) Microsoft MVP (11) AI (10) GitHub (10) GitHub Copilot (10) ASP.NET (9) Security (9) Synology (9) Architecture (8) Raspberry (8) Azure Functions (7) Cloudflare (7) Bicep (6)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact