QRCodeEncoderandDecoder 3.1.0

dotnet add package QRCodeEncoderandDecoder --version 3.1.0
                    
NuGet\Install-Package QRCodeEncoderandDecoder -Version 3.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="QRCodeEncoderandDecoder" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QRCodeEncoderandDecoder" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="QRCodeEncoderandDecoder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add QRCodeEncoderandDecoder --version 3.1.0
                    
#r "nuget: QRCodeEncoderandDecoder, 3.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package QRCodeEncoderandDecoder@3.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=QRCodeEncoderandDecoder&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=QRCodeEncoderandDecoder&version=3.1.0
                    
Install as a Cake Tool

Introduction The QR Code libraries allows your program to create (encode) QR Code image or, read (decode) an image containing one or more QR Codes. The attached source code is made of two solutions, a QR Code encoder solution and a QR Code decoder solution. The software was upgraded to VS 2022 .NET6.0. The source code is written in C#. It is an open-source code.

Please note the word "QR Code" is registered trademark of DENSO WAVE INCORPORATED.

Encoder Solution QRCodeEncoderLibrary: a class library project QRCodeEncoderDemo: a Windows Form demo program demonstrating how to encode a string or a byte array into a QR Code image file QRCodeConsoleDemo: a Windows console demo program demonstrating how to encode a text file or a binary file into a QR Code image file Decoder Solution QRCodeDecoderLibrary: a class library project QRCodeDecoderDemo: a demo program demonstrating how to decode image file containing a QR Code and retrieve the string or byte array. The image file source can be a disk file or a live video camera input. The video camera software is based on Direct Show Library. The QR Code encoder part of this library is included in the PDF File Writer C# Class Library article.

Installation The attached source code is made of two Visual Studio solutions. Each solution is made of one library project and demo/test project.

Integrating the code to your application requires the following steps. Install either the QRCodeEncoderLibrary.dll or the QRCodeDecoderLibrary.dll in your development area. Start the Visual Studio C# program and open your application. Go to the Solution Explorer, right click on References, and select Add Reference. Select the Browse tab and navigate your file system to the location of the required library. When your application is published, the relevant library file must be included and installed in the same folder as your executable (.exe) file.

Alternatively, you can copy the relevant library's source files into your project.

The relevant "using" statement must be added to all your source files:

C# using QRCodeEncoderLibrary; // or using QRCodeDecoderLibrary; QR Code QR Code stands for Quick Response Code. It is a two-dimensional barcode. Visually, it is a square made of small black and white square modules. The square is surrounded by a white quite zone. The QR Code is defined by the international standard ISO/IEC 18004. A free copy of this standard is available here.

The ISO standard document defines the QR Code as “QR Code is a matrix consisting of an array of nominally square modules arranged in an overall square pattern, including a unique finder pattern located at three corners of the symbol and intended to assist in easy location of its position, size and inclination. A wide range of sizes of symbol is provided for together with four levels of error correction. Module dimensions are user-specified to enable symbol production by a wide variety of techniques.”

The ISO standard 18004 is the best source of information for understanding the details of the QR Code. Searching the internet yields many more articles on this subject. Wikipedia article about QR Code can be viewed here.

The QR Code standard is a collection of 40 different squares varying in size. Each square has a version number from 1 to 40. The size of each square varies from 21 by 21 modules (version 1) to 177 by 177 modules (version 40). Each version has 4 more modules per side than the previous version.

C# Square-Dimension = 21 + 4 * (Version - 1) Some of the modules are fixed. The most obvious ones are the three-square finders. The remaining modules are divided between data and error correction. There are 4 levels of error correction:

L- Low will correct up to 7% errors M- Medium will correct up to 15% errors Q- Quarter will correct up to 25% errors H- High will correct up to 30% errors Each module in the data area represent one bit. Black module is 1 and white module is 0. The data area can be divided into segments. Each input segment byte array is encoded to data bits in one of three ways numeric, alphanumeric, and byte. Note: The QR Code standard has one more encoding method for Kanji characters. It is not supported by this project.

Numeric data: The segment is made only of digits 0–9. Three digits will be converted to 10 bits. Alphanumeric data: The segment is made of digits 0–9, upper case letters A–Z, and nine other characters [space, $ % * + - . / :]. Two alphanumeric characters will be converted to 11 bits. 8-bit byte data. The segment is not converted. There is one to one correspondence between input bits and modules. To encode a QR Code, you supply the data to be encoded and one of the four error correction codes. The system will calculate the smallest version number required to represent the data.

In addition to data, the QR Code can contains a ECI Assignment Number. The assignment number range is zero to 999999. The number is not part of the QR Code data. It is used for encoding data subject to alternative interpretations of byte values (e.g., alternative character sets).

The program analyzes each segment of data to find the "best" encoding. If you want to reduce the size of the QR Code and you have long strings of digits or alphanumeric data as defined above, then break your input into several strings or byte arrays. Some of these strings must be numeric only or Alphanumeric as defined above. During the decoding process, all resulted string segments will be concatenated together.

When the library decodes an image containing one or more QR Codes, the result will be an array of strings or array of byte arrays. Each array item is one QR Code.

QR Code Encoding The main class for encoding is QREncoder. It will convert a byte array or a text string into a QR Code image. To create a QR Code image, follow the steps:

Create QREncoder object. Set the two optional parameters. The error correction code and the ECI assignment number. This object is reusable. If you want to create many QR Codes, just reuse this object. There is no initialization or dispose requirement. The optional parameters will retain their value from the last run.

C# // create QR Code encoder object QRCodeEncoder Encoder = new(); Set the two optional parameters if required:

C# // Error correction // error correction low (7%) Encoder.ErrorCorrection = ErrorCorrection.L;

// or, error correction medium (15%) The Default Encoder.ErrorCorrection = ErrorCorrection.M;

// or, error correction quarter (25%) Encoder.ErrorCorrection = ErrorCorrection.Q;

// or, error correction high (30%) Encoder.ErrorCorrection = ErrorCorrection.H;

// ECI Assignment Value (default is -1 not used) // The ECI value is a number in the range of 0 to 999999. // or -1 if it is not used Encoder.ECIAssignValue = -1; Higher error correction percentage gives you better protection against damaged QR Code images. The cost is the increased size of the QR symbol.

Call one of the four Encode methods:

C# // single text string input public void Encode(string StringDataSegment);

// multiple text strings input public void Encode(string[] StringDataSegments);

// single byte array input public void Encode(byte[] ByteDataSegment);

// multiple byte arrays input public void Encode(byte[][] ByteDataSegments); If input data is text string, or array of text strings. The text will be converted to byte array using the following method.

C# // the encoder converts text string to byte array // using the conversion method byte[] ByteArray = Encoding.UTF8.GetBytes(Text); Effectively, the library software will convert the first and second Encode methods to the third and fourth methods respectively.

The QRCodeEncoderLibrary will scan each incoming data byte array segment to determine the best encoding method. The program will not attempt to break a single segment to minimize the size of the QR Code matrix. You can submit array of segments in such a way as to take advantage of long strings of numeric or alphanumeric data.

The Encode method returns a bool[,] a square matrix of Boolean elements array. The return two-dimensional bool array is available also as a public member QRCodeMatrix of the QREncode class. Each element represents black modules as true and white modules as false. The matrix dimension is given in public member QRCodeDimension. If encoding fails, an exception will be thrown.

The next step is to save the QR Code symbol to a file or, to create a Bitmap. The following example shows how to save the QRCodeMatrix to a PNG image file. Saving the QR Code image to PNG file DOES NOT require the use of Bitmap class and is suitable for net-core and net-standard. The PNG image file is significantly smaller than a PNG file created by Bitmap class in QRSaveBitmapImage.

C# // save image as png file // create save PNG image class // and load the QR Code matrix QRSavePngImage PngImage = new(QRCodeMatrix);

// set the module size in pixels PngImage.ModuleSize = ModuleSize;

// set the quiet zone in pixels PngImage.QuietZone = QuietZone;

// save the QR Code PNG image to file name // or to open file stream PngImage.SaveQRCodeToPngFile(Dialog.FileName); Save the QR Code using Bitmap class. Bitmap class allows you to select file format.

C# // save image as any file format supported by Bitmap class. // create image class for the QR Code matrix QRSaveBitmapImage Image = new(QRCodeMatrix);

// set the module size in pixels Image.ModuleSize = ModuleSize;

// set the quiet zone in pixels Image.QuietZone = QuietZone;

// save the QR Code image to file name // or to open file stream Image.SaveQRCodeToBitmapFile(Dialog.FileName, ImageFormat); Create PNG Image File using the CommandLine Class. The command line arguments are listed below. The arguments set the encoding options.

Command line arguments format:

Command Line: exefile [optional arguments] input-file output-file Output file must have .png extension Options format /code:value or -code:value (the : can be =) Error correction level. code=[error|e], value=low|l|medium|m|quarter|q|high|h], default=m Module size. code=[module|m], value=[1-100], default=2 Quiet zone. code=[quiet|q], value=[4-400], default=8, min=4*width ECI Assign Value: code=[value|v], value=[0-999999], default is no ECI value. Text file format. code=[text|t] see notes below. Input file is binary unless text file option is specified If input file format is text or t, the string will be encoded to byte array.

Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 385 9/19/2024

30th June, 2018: Version 1.0.0 Original version
20th July, 2018: Version 1.1.0 DirectShowLib consolidation
15th May, 2019: Version 2.0.0 The software was divided into two solutions. Encoder solution and Decoder solution. The encode solution is a multi-target solution. It will produce net462 netstandardapp2.0 libraries.
22nd July, 2019: Version 2.1.0 ECI Assignment Value support was added.
1st March: 2022: Version 3.0.0 upgrade to VS 2022 and .NET 6.0.
8 March 2022 Version 3.1.0 Fix for video decoder. Protect against unplugging the camera while using the demo. No change to encoder.
17 March 2022 Version 3.1.0 Encoder demo program. Add copy to clipboard feature.