DotCode Xamarin example app in Visual StudioDotCode .NET Standard & .NET Core Barcode Generator Code Examples

Buy License Download Demo Support 

.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:

  • The .NET Standard Barcode Generator is sold as a separate component that primarily generates images and does not require the use of barcode fonts, however, basic TrueType barcode fonts are provided.
  • This product is also included as a font encoder in all Developer License Packages of the DotCode Font and Encoder

Generate text for IDAutomation2D font or Unicode Image on a label

C# Code Example:
DotCode obj = new DotCode();
Label lblBarcode = new Label();
(if you want to use the IDAutomation2D font)
string textfont = obj.EncodeDotCode(dataToEncode, 0, applyTilde, encodingMode, Ratio, Columns, Rows, NewLine, Mask, QuietZone);
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.EncodeDotCode(dataToEncode, 2, applyTilde, encodingMode, Ratio, Columns, Rows, NewLine, Mask, QuietZone);
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 DotCode()
Dim lblBarcode as Label = new Label()
(if you want to use the IDAutomation2D font)
Dim textfont as string = obj.EncodeDotCode(dataToEncode, 0, applyTilde, encodingMode, Ratio, Columns, Rows, NewLine, Mask, QuietZone)
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.EncodeDotCode(dataToEncode, 1, applyTilde, encodingMode, Ratio, Columns, Rows, NewLine, Mask, QuietZone)
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:
DotCode obj = new DotCode();
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecSVG, "", QuietZone, ModuleSize);
or
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecHTML, "", QuietZone, ModuleSize);
WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentText = vectorimage;
VB.NET Code Example: 
Dim obj As New DotCode()
Dim vectorimage as string = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecSVG, "", QuietZone, ModuleSize)
or
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecHTML, "", QuietZone, ModuleSize)
Dim webBrowser as WebBrowser = new WebBrowser()
webBrowser.DocumentText = vectorimage

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

C# Code Example:
DotCode obj = new DotCode();
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecSVG, "", QuietZone, ModuleSize);
File.WriteAllText("DotCode.SVG", vectorimage);
or
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecEPS, "", QuietZone, ModuleSize);
File.WriteAllText("DotCode.EPS", vectorimage);
or
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecHTML, "", QuietZone, ModuleSize);
File.WriteAllText("DotCode.HTML", vectorimage);
VB.NET Code Example: 
Dim obj As New DotCode()
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecSVG, "", QuietZone, ModuleSize)
File.WriteAllText("DotCode.SVG", vectorimage)
or
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecEPS, "", QuietZone, ModuleSize)
File.WriteAllText("DotCode.EPS", vectorimage)
or
string vectorimage = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, VectorTypes.VecHTML, "", QuietZone, ModuleSize)
File.WriteAllText("DotCode.HTML", vectorimage)

Generate bitmap image as a byte array | image on a picture box control 

C# Code Example:
DotCode obj = new DotCode();
byte[] bmpstream = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, 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 DotCode()
Dim bmpstream() as Byte = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, 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:
DotCode obj = new DotCode();
byte[] bmpstream = obj.EncodeDotCode(dataToEncode,applyTilde, encodingMode, Ratio, Columns, Rows, Mask, 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 DotCode()
Dim bmpstream() as Byte = obj.EncodeDotCode(dataToEncode, applyTilde, encodingMode, Ratio, Columns, Rows, Mask, 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 (IDAutomation2D Font or a Unicode Monospace Font).
  • VectorType - (only for vector output) Indicates the type of vector image for output encoded text (SVG, EPS, or HTML).
  • ApplyTilde - Enables processing of the tilde character for purposes of encoding ASCII functions & GS1 application identifiers. NOTE: In DotCode the first FNC1 is assumed by the barcode reader if the data begins with a number.
  • EncodingMode - For future use only. Leave this setting in Auto mode, the default. Modes are used to encode the data.
  • 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.