←Select platform

BarcodeData Constructor(BarcodeSymbology,string)

Summary

Initializes a new instance of the BarcodeData class with specified symbology and ASCII text value.

Syntax
C#
VB
Objective-C
C++
Java
Public Function New( _ 
   ByVal symbology As BarcodeSymbology, _ 
   ByVal value As String _ 
) 
- (instancetype)initWithSymbology:(LTBarcodeSymbology)symbology  
                            value:(nullable NSString *)value 
public BarcodeData( 
  BarcodeSymbology symbology, 
  String value 
) 
public: 
BarcodeData(  
   BarcodeSymbology symbology, 
   String^ value 
) 

Parameters

symbology
Barcode symbology to use.

value
A String that specifies the ASCII text representation of the barcode data.

Remarks

This constructor initializes the BarcodeData member as follows:

s

Member Value
Symbology symbology
Bounds LeadRect.Empty
RotationAngle 0
BarWidthReduction 0
Byte array inside GetData The raw value of the bytes array in value. if this parameter is null, then the data is null too.
Value value.
Tag null (Nothing in Visual Basic)

To quickly construct a new BarcodeData object with a specific symbology and data as a raw byte array, use BarcodeData(BarcodeSymbology symbology, byte[] data) to construct a default BarcodeData, use BarcodeData().

To create an instance of BarcodeData suitable for writing for a specified symbology, use CreateDefaultBarcodeData.

Example

This example creates a BarcodeData with specified symbology and ASCII text. It then writes it to an image.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
public void BarcodeData_FromStringExample() 
{ 
   string outFileName = Path.Combine(LEAD_VARS.ImagesDir, @"MyBarcode.tif"); 
 
   // This is UPC data to save a a string 
   string dataString = "01234567890"; 
 
   // Create a BarcodeData object from this data 
   BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA, dataString); 
   data.Bounds = new LeadRect(0, 0, 400, 200); 
 
   // Make sure it is the same 
   Debug.Assert(data.Value == dataString); 
 
   // Write it to an image 
   BarcodeEngine engine = new BarcodeEngine(); 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      int resolution = 300; 
      LeadRect pixels = data.Bounds; 
      using (RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) 
      { 
         engine.Writer.WriteBarcode(image, data, null); 
 
         codecs.Save(image, outFileName, RasterImageFormat.Tif, 1); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Barcode 
Imports Leadtools.ImageProcessing 
 
Public Sub BarcodeData_FromStringExample() 
   Dim outFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.tif") 
 
   ' This is UPC data to save a a string 
   Dim dataString As String = "01234567890" 
 
   ' Create a BarcodeData object from this data 
   Dim data As New BarcodeData(BarcodeSymbology.UPCA, dataString) 
   data.Bounds = New LeadRect(0, 0, 400, 200) 
 
   ' Make sure it is the same 
   Debug.Assert(data.Value = dataString) 
 
   ' Write it to an image 
   Dim engine As New BarcodeEngine() 
   Using codecs As New RasterCodecs() 
      Dim resolution As Integer = 300 
      Dim pixels As LeadRect = data.Bounds 
      Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)) 
         engine.Writer.WriteBarcode(image, data, Nothing) 
 
         codecs.Save(image, outFileName, RasterImageFormat.Tif, 1) 
      End Using 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
c#[Silverlight C# Example] 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
using Leadtools.Examples; 
 
public void BarcodeData_FromStringExample() 
{ 
   // This is UPC data to save a a string 
   string dataString = "01234567890"; 
 
   // Create a BarcodeData object from this data 
   BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA, dataString); 
   data.Bounds = new LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel); 
 
   // Make sure it is the same 
   Debug.Assert(data.Value == dataString); 
 
   // Write it to an image 
   BarcodeEngine engine = new BarcodeEngine(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   int resolution = 300; 
   LeadRect pixels = data.Bounds.ToRectangle(resolution, resolution); 
   using (RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) 
   { 
      engine.Writer.WriteBarcode(image, data, null); 
 
      using (SampleImageStream outputStream = new SampleImageStream("MyBarcode.tif")) 
      { 
         codecs.Save(image, outputStream, RasterImageFormat.Tif, 1); 
      } 
   } 
} 
vb[Silverlight VB Example] 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms 
Imports Leadtools.Barcode 
Imports Leadtools.ImageProcessing 
 
Public Sub BarcodeData_FromStringExample() 
   ' This is UPC data to save a a string 
   Dim dataString As String = "01234567890" 
 
   ' Create a BarcodeData object from this data 
   Dim data As BarcodeData = New BarcodeData(BarcodeSymbology.UPCA, dataString) 
   data.Bounds = New LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel) 
 
   ' Make sure it is the same 
   Debug.Assert(data.Value = dataString) 
 
   ' Write it to an image 
   Dim engine As BarcodeEngine = New BarcodeEngine() 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   Dim resolution As Integer = 300 
   Dim pixels As LeadRect = data.Bounds.ToRectangle(resolution, resolution) 
   Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)) 
      engine.Writer.WriteBarcode(image, data, Nothing) 
 
      Using outputStream As SampleImageStream = New SampleImageStream("MyBarcode.tif") 
         codecs.Save(image, outputStream, RasterImageFormat.Tif, 1) 
      End Using 
   End Using 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly