Net.Codecrete.QrCodeGenerator
2.0.6
dotnet add package Net.Codecrete.QrCodeGenerator --version 2.0.6
NuGet\Install-Package Net.Codecrete.QrCodeGenerator -Version 2.0.6
<PackageReference Include="Net.Codecrete.QrCodeGenerator" Version="2.0.6" />
paket add Net.Codecrete.QrCodeGenerator --version 2.0.6
#r "nuget: Net.Codecrete.QrCodeGenerator, 2.0.6"
// Install Net.Codecrete.QrCodeGenerator as a Cake Addin #addin nuget:?package=Net.Codecrete.QrCodeGenerator&version=2.0.6 // Install Net.Codecrete.QrCodeGenerator as a Cake Tool #tool nuget:?package=Net.Codecrete.QrCodeGenerator&version=2.0.6
QR Code Generator for .NET
Open-source library for generating QR codes from text strings and byte arrays.
The library is built for .NET Standard 2.0 and therefore runs on most modern .NET platforms (.NET Core, .NET Framework, Mono etc.) including .NET 6 on all platforms.
It is mostly a translation of project Nayuki's Java version of the QR code generator. The project provides implementations for many more programming languages, and the Project Nayuki web site has additional information about the implementation.
Features
Core features:
- Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard
- Output formats: Raw modules/pixels of the QR symbol, SVG and XAML path. For raster bitmaps, additional code is provided. See below.
- Encodes numeric and special-alphanumeric text in less space than general text
- Open source code under the permissive MIT License
- Available as a NuGet package (named Net.Codecrete.QrCodeGenerator)
- Example code for WinForms, WPF, ASP.NET, ImageSharp, SkiaSharp etc.
Manual parameters:
- You can specify the minimum and maximum version number allowed, and the library will automatically choose the smallest version in the range that fits the data.
- You can specify the mask pattern manually, otherwise library will automatically evaluate all 8 masks and select the optimal one.
- You can specify an error correction level, or optionally allow the library to boost it if it doesn't increase the size (version).
- You can create a list of data segments manually and add ECI segments.
Optional advanced features:
- Encodes Japanese Unicode text in Kanji mode to save space compared to UTF-8 bytes
- Computes optimal segment mode switching for text with mixed numeric/alphanumeric/general/kanji parts
Getting started
Create a new Visual Studio project for .NET Core 3.1 (or higher) (File > New > Project... / Visual C# > .NET Core > Console App (.NET Core))
Add the library via NuGet:
Either via Project > Manage NuGet Packages... / Browse / search for qrcodegenerator / Install
Or by running a command in the Package Manager Console
Install-Package Net.Codecrete.QrCodeGenerator -Version 2.0.6
Add the code from the example below
Run it
API Documention
Examples
Simple operation
using Net.Codecrete.QrCodeGenerator;
namespace Examples
{
class SimpleOperation
{
static void Main()
{
var qr = QrCode.EncodeText("Hello, world!", QrCode.Ecc.Medium);
string svg = qr.ToSvgString(4);
File.WriteAllText("hello-world-qr.svg", svg, Encoding.UTF8);
}
}
}
Manual operation
using Net.Codecrete.QrCodeGenerator;
namespace Examples
{
class ManualOperation
{
static void Main()
{
var segments = QrSegment.MakeSegments("3141592653589793238462643383");
var qr = QrCode.EncodeSegments(segments, QrCode.Ecc.High, 5, 5, 2, false);
for (int y = 0; y < qr.Size; y++)
{
for (int x = 0; x < qr.Size; x++)
{
... paint qr.GetModule(x,y) ...
}
}
}
}
}
Requirements
QR Code Generator for .NET requires a .NET implementation compatible with .NET Standard 2.0 or higher, i.e. any of:
- .NET Core 2.0 or higher
- .NET Framework 4.6.1 or higher
- Mono 5.4 or higher
- Universal Windows Platform 10.0.16299 or higher
- Xamarin
Raster Images / Bitmaps
Starting with .NET 6, System.Drawing is only supported on Windows operating system and thus cannot be used for multi-platform libraries like this one. Therefore, ToBitmap()
has been removed and three options are now offered in the form of method extensions.
To use it:
- Select one of the imaging libraries below
- Add the NuGet dependencies to your project
- Copy the appropriate
QrCodeBitmapExtensions.cs
file to your project
Imaging library | Recommendation | NuGet dependencies | Extension file |
---|---|---|---|
System.Drawing | For Windows only projects | System.Drawing.Common |
QrCodeBitmapExtensions.cs |
SkiaSharp | For macOS, Linux, iOS, Android and multi-platform projects | SkiaSharp and SkiaSharp.NativeAssets.Linux (for Linux only) |
QrCodeBitmapExtensions.cs |
ImageSharp | Currently in beta state | SixLabors.ImageSharp.Drawing |
QrCodeBitmapExtensions.cs |
Using these extension methods, generating PNG images is straight-forward:
using Net.Codecrete.QrCodeGenerator;
namespace Examples
{
class PngImage
{
static void Main()
{
var qr = QrCode.EncodeText("Hello, world!", QrCode.Ecc.Medium);
qr.SaveAsPng("hello-world-qr.png", 10, 3);
}
}
}
Examples
Several example projects are provided:
Demo-QRCode-Variety: Demonstrates how QR codes with different encodings, error correction and masks can be generated. All QR codes are saved as SVG files.
Demo-WindowsPresentationFoundation: Demonstrates how QR codes can be used in WPF applications (incl. copying to the clipboard).
Demo-WinForms: Demonstrates how QR codes can be used in Windows Forms applications (incl. copying to the clipboard).
Demo-ASP.NET-Core: Demonstrates how to create QR codes in a web application implemented using ASP.NET Core.
Demo-VCard: Demonstrates how contact data (similar to business cards) can be saved in a QR Code using the VCard standard.
Demo-System-Drawing: Demonstrates how a QR code can be saved a PNG file, using the System.Drawing classes, which have become a Windows only technology starting with .NET 6.
Demo-SkiaSharp: Demonstrates how a QR code can be saved a PNG file, using the SkiaSharp multi-platform raster image library.
Demo-ImageSharp: Demonstrates how a QR code can be saved a PNG file, using the ImageSharp raster image library. Additionally, a QR code with an image in the center is created.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages (13)
Showing the top 5 NuGet packages that depend on Net.Codecrete.QrCodeGenerator:
Package | Downloads |
---|---|
Codecrete.SwissQRBill.Core
Generates the new QR bills for invoicing in Switzerland. The Swiss QR bill library: - is a minimal, platform-independent library supporting PDF and SVG (see homge page for PNG and EMF), - parses the invoice data embedded in the QR code, - generates payment slips (105mm by 210mm), A4 sheets or QR codes, - is multilingual: German, French, Italian, English, Romansh, - validates the invoice data and provides detailed validation information, - adds and retrieves structured bill information (according to Swico S1), - is easy to use and comes with many examples, - is small and fast, - is free – even for commecial use (MIT License), - is built for .NET Standard 2.0 and runs on all modern .NET platforms. See home page https://github.com/manuelbl/SwissQRBill.NET for examples and other library versions. |
|
Aiursoft.WebTools
A tool for web development. |
|
NineDigit.eKasa
eKasa PPEKK solution by Nine Digit, s.r.o. |
|
LeadSoft.Common.Library
LeadSoft® Common utilities methods and classes. |
|
SqrlForNet
SQRL for the .Net Standard runtimes. Secure Quick Reliable Login is a highly secure user privacy based authentication system that removes the need for users to have more than one password for a global identity https://www.grc.com/sqrl/sqrl.htm for more information of the protocal. |
GitHub repositories (7)
Showing the top 5 popular GitHub repositories that depend on Net.Codecrete.QrCodeGenerator:
Repository | Stars |
---|---|
BeyondDimension/SteamTools
🛠「Watt Toolkit」是一个开源跨平台的多功能 Steam 工具箱。
|
|
LagrangeDev/Lagrange.Core
An Implementation of NTQQ Protocol, with Pure C#, Derived from Konata.Core
|
|
CHKZL/DDTV
可对阿B进行直播多窗口观看、开播提醒、自动录制、合并、转码的跨平台工具
|
|
neozhu/visitormanagement
helps in managing visitors visiting the institutions for various reasons. It allows visitors to check-in digitally to eliminate the tedious registeration and other paperwork. Additionally, it also keeps a track of every individual inside the campus and their timings. Institutions has guards who enter their detail in some notebooks to keep a log which are practically impossible to reconcile. It is really unpleasent and hectic for visitor to stand at the gate and give details about the visit. To ease the process of registeration, Entry-In, Entry-Out, time tracking and logging the history, this VMS can be of great use!!
|
|
manuelbl/QrCodeGenerator
QR Code Generator for .NET
|
Version | Downloads | Last updated |
---|---|---|
2.0.6 | 2,703 | 12/7/2024 |
2.0.5 | 274,559 | 3/23/2024 |
2.0.4 | 450,481 | 10/13/2023 |
2.0.3 | 645,611 | 7/4/2022 |
2.0.2 | 1,054 | 7/4/2022 |
2.0.1 | 332,221 | 12/10/2021 |
2.0.0 | 295,494 | 11/14/2021 |
2.0.0-rc.1 | 7,510 | 8/24/2021 |
1.6.1 | 234,074 | 10/19/2020 |
1.6.0 | 22,596 | 7/5/2020 |
1.5.0 | 120,273 | 10/20/2019 |
1.4.1 | 11,494 | 2/20/2019 |
1.4.0 | 1,944 | 2/10/2019 |
New in releases 2.0.x:
- Fully compatible with .NET 6 (no longer depends on System.Drawing)
- Separate ToBitmap() implementations for System.Drawing, SkiaSharp and ImageSharp
- Documentation included into NuGet package
- QR code as geometric path suitable for SVG and XAML
- Very compact SVGs
- BMP bitmap generation
- Fix for SVG generation with Norwegian locale
- Enable trimming for .NET 6
- Fix for `IndexOutOfRangeException`