Skip to content

Repository files navigation

QRCoder.Core - QR Code Generator Library

LicenseBuildCode QualitySecurity ScancodecovNuGetQuality GateSecurity RatingCoverageGitHub issuesGitHub top language

Leia em Portugues (pt-BR)

Documentation

Project Description

QRCoder.Core is a cross-platform .NET library for QR Code generation using SkiaSharp for image rendering. Compatible with Windows, Linux, macOS, and mobile (Xamarin / MAUI).

Based on QRCoder. Developed and maintained by AFONSOFT.

Supported Output Formats

FormatClassDescription
SKBitmapQRCodeSkiaSharp bitmap image (cross-platform)
PNGPngByteQRCodePNG byte array (no System.Drawing needed)
SVGSvgQRCodeScalable vector graphics string
PDFPdfByteQRCodePDF document as byte array
ASCIIAsciiQRCodeASCII art for terminal output
Base64Base64QRCodeBase64-encoded image string
PostscriptPostscriptQRCodePostscript/EPS format
ArtisticArtQRCodeCustom QR with rounded dots and backgrounds
BMP BytesBitmapByteQRCodeBitmap byte array

Supported Payload Types

The PayloadGenerator class provides formatted strings for common QR code use cases:

PayloadDescription
UrlWebsite URL
WiFiWi-Fi network credentials
MailEmail with subject and body
SMSSMS message
PhoneNumberPhone number
MMSMultimedia message
GeolocationGPS coordinates
CalendarEventCalendar event (iCal/vEvent)
ContactDatavCard / MeCard contact
BitcoinLikeCryptoCurrencyAddressBitcoin/crypto payment
GirocodeEuropean SEPA payment
BezahlCodeGerman payment standard
SwissQrCodeSwiss QR-bill payment
OneTimePasswordTOTP/HOTP for 2FA
ShadowSocksConfigShadowSocks proxy config
BookmarkBrowser bookmark
SkypeCallSkype call link
WhatsAppMessageWhatsApp message
RussiaPaymentOrderRussian payment order
SlovenianUpnQrSlovenian UPN QR payment

Test Coverage

MetricCoverageStatus
Line Coverage96.9%Excellent
Branch Coverage92.6%Excellent
Method Coverage96.0%Excellent
Total Tests502All Passed

Project Status

Complete - Actively maintained with modern CI/CD pipelines.

Business Vision

QRCoder.Core provides a lightweight, cross-platform foundation for QR code generation that can be embedded in any .NET product — from mobile and web backends to desktop and CLI tooling. The goal is to remove platform-specific graphics dependencies while offering a predictable, extensible API for multiple output formats and industry-standard payloads.

Technical Vision

The library is organized as a Clean Architecture pipeline:

  • Generation: QRCodeGenerator builds an abstract QRCodeData matrix (models).
  • Payloads: PayloadGenerator formats standard data strings (Wi-Fi, vCard, SEPA, etc.) without coupling to rendering.
  • Rendering: AbstractQRCode implementations produce output formats (PNG, SVG, PDF, ASCII, Base64, Postscript, Art, BMP) using SkiaSharp for cross-platform bitmap rendering.
  • Dependency rule: Abstractions and Models have no external dependencies; Renderers and Generators depend only on Models and Abstractions.
  • Quality gates: build with zero warnings, xUnit tests with ~97% line coverage, and static analysis via SonarCloud / Codecov / Snyk.

Prerequisites

This library is compatible with multiple .NET versions:

  • .NET Standard 2.1 — Maximum compatibility
  • .NET 8.0 — LTS recommended
  • .NET 10.0 — Latest version
  • .NET Framework 4.8 — Legacy support

Technologies Used:

  • C# — Primary programming language
  • SkiaSharp — Cross-platform graphics library for rendering
  • SkiaSharp.Views — SkiaSharp UI components
  • System.Text.Encoding.CodePages — Additional code page support
  • Microsoft.Extensions.ObjectPool — Reusable buffer pooling
  • xUnit — Unit testing framework
  • Shouldly — Assertion library
  • coverlet — Cross-platform code coverage
  • dotnet-reportgenerator-globaltool — Coverage report generation
  • GitHub Actions — CI/CD automation
  • SonarCloud — Static analysis and quality gates
  • Codecov — Coverage reporting
  • Snyk — Security vulnerability scanning

Installation

NuGet Package Manager (recommended)

Install-Package QRCoder.Core

.NET CLI

dotnet add package QRCoder.Core

PackageReference

<PackageReferenceInclude="QRCoder.Core"Version="2.0.1" />

Quick Start

Generate your first QR code with just a few lines of code:

usingSystem;usingSystem.IO;usingQRCoder.Core.Generators;usingQRCoder.Core.Models;usingQRCoder.Core.Renderers;usingSkiaSharp;// Create the QR Code generatorusingvargenerator=newQRCodeGenerator();usingvardata=generator.CreateQrCode("https://github.com/afonsoft/QRCoder.Core",QRCodeGenerator.ECCLevel.M);// Render as PNG bytes (cross-platform, no System.Drawing needed)usingvarpng=newPngByteQRCode(data);byte[]pngBytes=png.GetGraphic(10);File.WriteAllBytes("qrcode.png",pngBytes);// Or render as SKBitmapusingvarqrCode=newQRCode(data);usingvarbitmap=qrCode.GetGraphic(10);

More Output Formats

usingSystem;usingSystem.IO;usingQRCoder.Core.Generators;usingQRCoder.Core.Models;usingQRCoder.Core.Renderers;usingSkiaSharp;// SVG outputusingvarsvg=newSvgQRCode(data);stringsvgString=svg.GetGraphic(10);// ASCII output (great for terminal)usingvarascii=newAsciiQRCode(data);Console.WriteLine(ascii.GetGraphic(1));// PDF outputusingvarpdf=newPdfByteQRCode(data);byte[]pdfBytes=pdf.GetGraphic(5);// Base64 PNG (embed in HTML)usingvarb64=newBase64QRCode(data);stringbase64Img=b64.GetGraphic(10);// Use in HTML: <img src="data:image/png;base64,{base64Img}" />// With custom colorsusingvarcolorQr=newQRCode(data);usingvarcolorBmp=colorQr.GetGraphic(10,"#1a1a2e","#e0e0e0");// Postscript / EPSusingvarps=newPostscriptQRCode(data);stringpsString=ps.GetGraphic(5);

Payload Examples

usingSystem;usingSystem.IO;usingQRCoder.Core.Generators;usingQRCoder.Core.Models;usingQRCoder.Core.Renderers;usingSkiaSharp;// Wi-Fi QR CodevarwifiPayload=newPayloadGenerator.WiFi("MyNetwork","MyPassword",PayloadGenerator.WiFi.Authentication.WPA);usingvargen=newQRCodeGenerator();usingvarwifiData=gen.CreateQrCode(wifiPayload.ToString(),QRCodeGenerator.ECCLevel.M);// URL QR CodevarurlPayload=newPayloadGenerator.Url("https://github.com/afonsoft/QRCoder.Core");usingvarurlData=gen.CreateQrCode(urlPayload.ToString(),QRCodeGenerator.ECCLevel.M);// Email QR CodevarmailPayload=newPayloadGenerator.Mail("test@example.com","Subject","Body text");usingvarmailData=gen.CreateQrCode(mailPayload.ToString(),QRCodeGenerator.ECCLevel.M);// Phone NumbervarphonePayload=newPayloadGenerator.PhoneNumber("+5511999999999");usingvarphoneData=gen.CreateQrCode(phonePayload.ToString(),QRCodeGenerator.ECCLevel.M);// Contact Card (vCard)varcontactPayload=newPayloadGenerator.ContactData(PayloadGenerator.ContactData.ContactOutputType.VCard3,"Doe","John",phone:"+5511999999999",email:"john.doe@example.com");usingvarcontactData=gen.CreateQrCode(contactPayload.ToString(),QRCodeGenerator.ECCLevel.M);

See the full Usage Guide for all output formats, payload types, advanced settings, and error correction levels.

Error Correction Levels

LevelRecoveryUse Case
ECCLevel.L~7%Maximum data capacity
ECCLevel.M~15%General purpose (recommended)
ECCLevel.Q~25%Higher reliability
ECCLevel.H~30%Maximum error recovery (logos, artistic QR)

Repository Structure

.
├── QRCoder.Core/ # Core library source code
│ ├── Abstractions/ # Abstract base class and contracts
│ │ └── AbstractQRCode.cs # Base class for all renderers
│ ├── Models/ # QR code data model and value objects
│ │ ├── QRCodeData.cs # QR code data structure
│ │ └── Size.cs # Rendering size value object
│ ├── Generators/ # QR code generation engine
│ │ ├── QRCodeGenerator.cs # Main QR code data generator
│ │ └── PayloadGenerator.cs# Payload formatters (WiFi, URL, etc.)
│ ├── Renderers/ # Output format renderers
│ │ ├── QRCode.cs # SKBitmap renderer
│ │ ├── PngByteQRCode.cs # PNG byte array renderer
│ │ ├── SvgQRCode.cs # SVG string renderer
│ │ ├── PdfByteQRCode.cs # PDF byte array renderer
│ │ ├── AsciiQRCode.cs # ASCII art renderer
│ │ ├── Base64QRCode.cs # Base64 image renderer
│ │ ├── PostscriptQRCode.cs# Postscript/EPS renderer
│ │ ├── ArtQRCode.cs # Artistic QR code renderer
│ │ └── BitmapByteQRCode.cs# BMP byte array renderer
│ ├── Extensions/ # SkiaSharp and helper extensions
│ ├── Exceptions/ # Custom exceptions
│ └── Assets/ # NuGet assets
├── QRCoder.Core.Tests/ # Unit tests (502 tests)
├── QRCoder.Core.Benchmarks/ # Performance benchmarks
├── docs/ # Usage guides
│ ├── en-US/usage-guide.md # English usage guide
│ └── pt-BR/guia-de-uso.md # Portuguese usage guide
├── .github/workflows/ # CI/CD pipelines
├── CHANGELOG.md # Version history
└── README.md / README.pt-br.md# English and Portuguese documentation

CI/CD and Build

This project uses a complete CI/CD pipeline with GitHub Actions:

Available Workflows

  • Build & Pack — Main build with tests, coverage, and package creation
  • Code Quality — Code analysis with Qodana and SonarCloud
  • Security Scans — Security analysis with CodeQL, Snyk, and SonarCloud
  • Publish NuGet — Automatic publishing to NuGet.org and GitHub Packages
  • CI Build & Test — Continuous build and automated testing

Running Tests Locally

# Build the project
dotnet build QRCoder.Core.sln --configuration Release
# Run all tests with coverage
dotnet test QRCoder.Core.Tests/QRCoder.Core.Tests.csproj \
--configuration Release \
--logger "trx;LogFileName=test-results.trx" \
--results-directory TestResults \
--collect:"XPlat Code Coverage"# Generate HTML coverage report
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator \
-reports:"TestResults/**/coverage.cobertura.xml" \
-targetdir:"TestResults/CoverageReport" \
-reporttypes:"Html;XmlSummary;TextSummary"# View report: open TestResults/CoverageReport/index.html

Contributing

  1. Create a branch from main:

    git checkout -b feature/your-feature
  2. Make your changes following code conventions

  3. Automated workflows will run:

    • Build & Pack — Validates your code
    • Code Quality — Analyzes quality
    • Security Scan — Checks security
  4. Pull Request: Create a PR to main

  5. Review and Merge: After approval, your code will be merged

Developers

  • Afonso Dutra Nogueira Filho (AFONSOFT) — Lead developer

Star History

Star History Chart

StarMapper

StarMapper Map

License

This project is licensed under the MIT License. See the LICENSE.txt file for details.

Changelog

See the full CHANGELOG.md for the complete version history.

[2.0.1] - 2026-07-11

Added

  • XML documentation for all public APIs (CS1591 removed from NoWarn).
  • Repository structure, business vision, and technical vision sections in README.
  • BDDTests.cs with BDD-style Given/When/Then tests for QR code generation and rendering.

Changed

  • Bumped package version to 2.0.1.
  • Updated CI, NuGet, SonarCloud, and Codecov badges in README files.
  • Updated SonarCloud links to the correct project (afonsoft_QRCoder.Core).
  • Consolidated CHANGELOG.md following Keep a Changelog and SemVer.

Fixed

  • Broken NuGet badge (now using shields.io).
  • Broken CI build badge (now using ci-build-test.yml).
  • SonarQube S2184 (integer division in PdfByteQRCode media size).
  • SonarQube S4136 by grouping GetGraphic overloads in QRCode and PdfByteQRCode.

[2.0.0] - 2026-05-10

Changed

  • Reorganized codebase with SOLID and Clean Architecture folder structure.
  • Multi-language documentation (en-US default + pt-BR).
  • Updated target frameworks: .NET Standard 2.1, .NET 8.0, .NET 10.0, .NET Framework 4.8.

[1.0.8] - 2026-02-18

Added

  • SkiaSharp native library handling for Linux CI.
  • Consolidated publish workflows.

[1.0.5] - 2025-07-13

Changed

  • Migrated rendering to SkiaSharp.
  • General project and documentation adjustments.

[1.0.3] - 2024-04-01

Changed

  • Dependency updates.

Fixed

  • Action corrections.

About

QRCoder.Core is a simple library, written in C#.NET

Resources

Stars

7 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages