QR Code .NET Standard in XamarinQR Code .NET Standard & .NET Core Barcode Generator Source Code Examples

Buy License Download Demo Support

QR Code .NET Standard 2.0 Integration

The following code is provided to assist with implementation. Please refer to the Barcode Generation and Xamarin examples provided in the download package for actual working app examples. The included .NET Standard 2.0 source code and assembly supports .NET Core 2.0, .NET Framework, Mono, Xamarin, Unity, and Universal Windows Platform.

Availability:

  • This product is provided as a separate component that primarily generates images and does not require the use of barcode fonts, however, basic barcode fonts are provided.
  • This product is also included as a font encoder in all Developer License Packages of the QR-Code font package. 

Generate text for IDAutomation2D font or Unicode Image on a label

C# Code Example:
QRCode obj = new QRCode();
Label lblBarcode = new Label();
(if you want to use the IDAutomation2D font)
string textfont = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, OutputTypes.IDA2DFont, bestMask);
lblBarcode.Font = new System.Drawing.Font("IDAutomation2D", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
or (if you want to use Courier New as Unicode Image)
string textfont = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, OutputTypes.IDAMonospaceFont, bestMask);
lblBarcode.Font = new System.Drawing.Font("Courier New", 6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lblBarcode.Text = textfont;
VB.NET Code Example: 
Dim obj As New QRCode()
Dim lblBarcode as Label = new Label()
(if you want to use the IDAutomation2D font)
Dim textfont as string = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, OutputTypes.IDA2DFont, bestMask)
lblBarcode.Font = new System.Drawing.Font("IDAutomation2D", 8.25, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
or (if you want to use Courier New as Unicode Image)
Dim textfont as string = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, OutputTypes.IDAMonospaceFont, bestMask)
lblBarcode.Font = new System.Drawing.Font("Courier New", 6, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
lblBarcode.Text = textfont

Generate SVG or HTML output on a web browser control

C# Code Example:
QRCode obj = new QRCode();
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecSVG, "", QuietZone, ModuleSize);
or 
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecHTML, "", QuietZone, ModuleSize);
WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentText = vectorimage;
VB.NET Code Example: 
Dim obj As New QRCode()
Dim vectorimage as string = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecSVG, "", QuietZone, ModuleSize)
or 
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecHTML, "", QuietZone, ModuleSize)
Dim webBrowser as WebBrowser = new WebBrowser()
webBrowser.DocumentText = vectorimage

Generate SVG, EPS or HTML output to save as a file

C# Code Example:
QRCode obj = new QRCode();
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecSVG, "", QuietZone, ModuleSize);
File.WriteAllText("QRCode.SVG", vectorimage);
or
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecEPS, "", QuietZone, ModuleSize);
File.WriteAllText("QRCode.EPS", vectorimage);
or
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecHTML, "", QuietZone, ModuleSize);
File.WriteAllText("QRCode.HTML", vectorimage);
VB.NET Code Example: 
Dim obj As New QRCode()

string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecSVG, "", QuietZone, ModuleSize)
File.WriteAllText("QRCode.SVG", vectorimage)
or
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecEPS, "", QuietZone, ModuleSize)
File.WriteAllText("QRCode.EPS", vectorimage)
or
string vectorimage = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, VectorTypes.VecHTML, "", QuietZone, ModuleSize)
File.WriteAllText("QRCode.HTML", vectorimage)

Generate bitmap Image as a byte array | output on a picture box control 

C# Code Example:
QRCode obj = new QRCode();
byte[] bmpstream = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, QuietZone, ModuleSize);
PictureBox picImage = new PictureBox();
picImage.AutoSize = true;
using (MemoryStream mStream = new MemoryStream(bmpstream))
{
Image img1 = Image.FromStream(mStream);
picImage.Image = img1;
}
VB.NET Code Example: 
Dim obj As New QRCode()
Dim bmpstream() as Byte = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, QuietZone, ModuleSize)
Dim picImage as PictureBox = new PictureBox()
picImage.AutoSize = true
Dim mStream As MemoryStream = New MemoryStream(bmpstream)
Dim img1 As Image = Image.FromStream(mStream)
picImage.Image = img1

Generate BMP|PNG|GIF|JPEG image to save as a file

C# Code Example:
QRCode obj = new QRCode();
byte[] bmpstream = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, QuietZone, ModuleSize);
MemoryStream mStream = new MemoryStream(bmpstream); Image imgSave = Image.FromStream(mStream); if (doBMP) { // BMP File.WriteAllBytes("ImageFile.bmp", bmpstream);
} else if (doPNG) { // PNG imgSave.Save(mStream, ImageFormat.Png); bmpstream = mStream.ToArray(); File.WriteAllBytes("ImageFile.png", bmpstream);
} else if (doGIF) { // GIF imgSave.Save(mStream, ImageFormat.Gif); bmpstream = mStream.ToArray(); File.WriteAllBytes("ImageFile.gif", bmpstream); } else if (doJPG) { // JPEG imgSave.Save(mStream, ImageFormat.Jpeg); bmpstream = mStream.ToArray(); File.WriteAllBytes("ImageFile.jpg", bmpstream); }
VB.NET Code Example: 
Dim obj As New QRCode()
Dim bmpstream() as Byte = obj.EncodeQR(dataToEncode, applyTilde, encodingMode, Version, errorCorrectionLevel, bestMask, QuietZone, ModuleSize)
Dim mStream As MemoryStream = New MemoryStream(bmpstream) Dim imgSave As Image = Image.FromStream(mStream) If (doBMP) Then '' BMP File.WriteAllBytes("ImageFile.bmp", bmpstream) ElseIf (doPNG) Then '' PNG imgSave.Save(mStream, ImageFormat.Png) bmpstream = mStream.ToArray() File.WriteAllBytes("ImageFile.png", bmpstream) ElseIf (doGIF) Then '' GIF imgSave.Save(mStream, ImageFormat.Gif) bmpstream = mStream.ToArray() File.WriteAllBytes("ImageFile.gif", bmpstream)
ElseIf (doJPG) Then '' JPEG imgSave.Save(mStream, ImageFormat.Jpeg) bmpstream = mStream.ToArray() File.WriteAllBytes("ImageFile.jpg", bmpstream)
End If

Common Parameters

  • DataToEncode - The data that is encoded in the barcode.
  • OutType – (only for font output) Indicates the type of encoded text output for the barcode font (IDAutomation font, Unicode Monospace).
  • VectorType – (only for vector output) Indicates the type of vector image for output encoded text (SVG, EPS or HTML).
  • ApplyTilde - Enables processing of tilde for purposes of encoding ASCII functions, GS1 application identifiers and image overlay as Center Override.
  • EncodingMode - Various modes used to Data represented in the symbol may be encoded by one of these types: Numeric, Alphanumeric or Binary.
  • Version - Represents the various sizes of the symbol.
  • ErrorCorrectionLevel - Four levels of error correction, which allow verification of data and recovery in the event that part of the symbol is physically damaged.
  • BestMask - Use a best mask for pattern in the QRCode.
  • QuietZone - Defines the size of a blank zone around the code.
  • ModuleSize - Defines the size of each module in pixels. The ModuleSize parameter can control the size of BMP images, however, a multiplicative factor is added to avoid a strange "blur" effect that occurs with low values with SVG and HTML images.

NOTE: Portions of this product utilize IDAutomation USA Patent 7,637,436.

.NET Standard 1.0 Tutorial (Legacy)

This installation example is using the "WorkingWithFonts" Xamarin sample project that was created in Visual Studio 2017 Community Version with Xamarin and C#. Refer to the compatibility chart for use in other development environments.

  1. Download and extract the package into a directory on the development computer.
  2. Copy the DLL that is to be used to the project directory. Do not copy the components to the bin directory; upon compiling the project, the DLL in the project folder will be copied to the appropriate bin folder with the associated files automatically. The application must be able to access the control after it is installed from a local drive for security purposes.
  3. Select Project - Add Reference by opening Solution Explorer, right-click on References and Add Reference. Using the open dialog, Browse for the specific DLL file and add it to the project.
    Add Reference Dialog in Visual Studio
  4. Place the IDAutomation 2D font in the respective (Android, iOS, UWP, etc) Assets folder, within the project. A standard system font may also be used, however, the IDAutomation 2D font will usually produce cleaner images.
    Place the IDAutomation 2D font in the respective (Android, iOS, UWP, etc) Assets folder.
  5. Display the result of the EncodeQR method in a label on a form with the IDAutomation2D font. To understand more about how to display the barcode image, refer to the FontPageCs.cs file, located in the WorkingWithFonts example project.

If it is desired to use the .cs file instead of the DLL, the procedure below should be followed. The Unlimited Developer License is required to obtain the C# file.

  1. Within Solution Explorer, choose Add > Existing Item > navigate to the .cs file and choose Add.
  2. Clean and rebuild the project or solution.
  3. Add the following to the top of the FrontPage.cs file:
    using IDAutomation.NetStandard;
  4. Within the project, add the local instantiation, for example:
    QRCode qr = new QRCode(); //local instance
  5. The function will now be available, for example:
    Text = qr.EncodeQR(DataToEncode, true, EncodingModes.Byte, Versions.AUTO, ErrorCorrectionLevels.M, OutputTypes.IDA2DFont);

Implementation Code Examples

using IDAutomation.NetStandard;
 QRCode qr = new QRCode();

C# Example - IDAutomation2D Font in Xamarin.Forms Label:

var labelEncodedText = new Label {
 Text = qr.EncodeQR(DataToEncode, true, EncodingModes.Byte, Versions.AUTO, ErrorCorrectionLevels.M, OutputTypes.IDA2DFont),
 
  TextColor = Color.White,
 
  //Embedded IDAutomation2D Font
  FontFamily = Device.OnPlatform(
   "IDAutomation2D", // iOS
   "IDAutomation2D.ttf#IDAutomation2D", // Android
   "Assets/Fonts/IDAutomation2D.ttf#IDAutomation2D" //Windows
  ),
 
  VerticalOptions = LayoutOptions.Center,
  HorizontalOptions = LayoutOptions.Center,
};

C# Example - System Font (Proportional) in Xamarin.Forms Label:

//Formatted Label to produce barcode characters with varying colors (makes spaces transparent)
var labelFormatted = new Label();
var fs = new FormattedString();
 
//Barcode String
var bc = qr.EncodeQR(DataToEncode, true, EncodingModes.Byte, Versions.AUTO, ErrorCorrectionLevels.M, OutputTypes.IDAProportionalFont);
 
//Barcode Color
var colorFront = Color.White;
 
//Space Color (transparent is default)
var colorBack = Color.Transparent;
 
//Font Size for barcode
var fntSize = 7;
 
//Vertical proportionality (added to height)
var fntExtra = .3;
 
//Loop through and color the barcode
foreach(char c in bc) {
 if (c != (char)(9617)) {
  fs.Spans.Add(new Span {
   Text = c.ToString(), ForegroundColor = colorFront, FontSize = fntSize
  });
 } else {
  fs.Spans.Add(new Span {
   Text = c.ToString(), ForegroundColor = colorBack, FontSize = (fntSize + fntExtra)
  });
 }
 
}
 
//Assigns formatted text to label
labelFormatted.FormattedText = fs;

Functions and Parameters

Namespace:  IDAutomation.NetStandard
Assembly:  IDAutomation.NetStandard.QRCode (in IDAutomation.NetStandard.QRCode.dll)

public string EncodeQR(
 string DataToEncode,
 bool ApplyTilde = true,
 EncodingModes EncodingMode = EncodingModes.Byte,
 Versions Version = Versions.AUTO,
 ErrorCorrectionLevels ErrorCorrectionLevel = ErrorCorrectionLevels.M,
 OutputTypes OutputType = OutputTypes.IDA2DFont,
 bool BestMask = true
)  
Parameter Optional Type Notes
Return Value No String 2D font text that creates an image when combined with the IDAutomation2D font (the default), native text image which uses a proportional system font, or a native text image which uses a mono-spaced font such as Courier New or Consolas.
DataToEncode No String The data that is encoded in the barcode.
ApplyTilde Yes Boolean Enables processing of tilde and parentheses characters for purposes of encoding ASCII functions and GS1 application identifiers.
EncodingMode Yes IDAutomation.NetStandard.EncodingModes The mode of compaction used to encode data in the symbol. Valid values are Byte, Alphanumeric, and Numeric mode.
Version Yes IDAutomation.NetStandard.Versions Sets the size of the symbol; valid values are from 01 (21X21) to 40 (177X177); the default value of "Auto" is used for automatic formatting.
ErrorCorrectionLevel Yes IDAutomation.NetStandard.ErrorCorrectionLevels Four levels of Reed-Solomon error correction, which allow verification of data and recovery in the event that part of the symbol is physically damaged.
OutputType
or OutType
Yes IDAutomation.NetStandard.OutputTypes Determines the Return Value. (Refer to the notes about Return Value)
VectorType
Yes IDAutomation.NetStandard.VectorTypes
Only for vector output, Indicates the type of vector image for output encoded text (SVG, EPS or HTML).
BestMask Yes Boolean Use a best mask for pattern in the QR-Code.

Support

Free product support may be obtained by reviewing the knowledge base articles that are documented below and by searching the resolved public forum threads. Priority phone, email and forum support is provided up to 30 days after purchase. Additional priority phone, email and forum support may be obtained if the Priority Support and Upgrade Subscription is active.