LinearBarcodeStructure Class
In This Topic
Stores the structure of linear barcode (Code 39, Code 128, EAN 13, etc).
Object Model
Syntax
Example
This C#/VB.NET code shows how to get information about bar widths of 1D linear barcode and output information to console.
''' <summary>
''' Gets information about bar widths of 1D linear barcode and outputs information to the console.
''' </summary>
''' <param name="barcodeType">The barcode type.</param>
''' <param name="value">The barcode value.</param>
Public Shared Sub PrintLinearBarcodeBars(barcodeType As Vintasoft.Barcode.BarcodeType, value As String)
Dim barWidths As Integer() = GetLinearBarcodeBars(barcodeType, value)
For Each barWidth As Integer In barWidths
System.Console.Write(barWidth.ToString() & " ")
Next
End Sub
''' <summary>
''' Returns information about bar widths of 1D linear barcode.
''' </summary>
''' <param name="barcodeType">The barcode type.</param>
''' <param name="value">The barcode value.</param>
''' <returns>The array that contains bar widths.</returns>
Public Shared Function GetLinearBarcodeBars(barcodeType As Vintasoft.Barcode.BarcodeType, value As String) As Integer()
' create barcode writer
Using writer As New Vintasoft.Barcode.BarcodeWriter()
writer.Settings.Barcode = barcodeType
writer.Settings.Value = value
' generate structure of 1D linear barcode
Dim barcode As Vintasoft.Barcode.BarcodeStructure.LinearBarcodeStructure = DirectCast(writer.GetBarcodeStructure(), Vintasoft.Barcode.BarcodeStructure.LinearBarcodeStructure)
' get information about bars of 1D linear barcode
Dim bars As Vintasoft.Barcode.BarcodeStructure.BarcodeBarElement() = barcode.GetBars()
' copy bar widths to an array
Dim result As Integer() = New Integer(bars.Length - 1) {}
For i As Integer = 0 To bars.Length - 1
result(i) = bars(i).Width
Next
Return result
End Using
End Function
/// <summary>
/// Gets information about bar widths of 1D linear barcode and outputs information to the console.
/// </summary>
/// <param name="barcodeType">The barcode type.</param>
/// <param name="value">The barcode value.</param>
public static void PrintLinearBarcodeBars(Vintasoft.Barcode.BarcodeType barcodeType, string value)
{
int[] barWidths = GetLinearBarcodeBars(barcodeType, value);
foreach (int barWidth in barWidths)
System.Console.Write(barWidth.ToString() + " ");
}
/// <summary>
/// Returns information about bar widths of 1D linear barcode.
/// </summary>
/// <param name="barcodeType">The barcode type.</param>
/// <param name="value">The barcode value.</param>
/// <returns>The array that contains bar widths.</returns>
public static int[] GetLinearBarcodeBars(Vintasoft.Barcode.BarcodeType barcodeType, string value)
{
// create barcode writer
using (Vintasoft.Barcode.BarcodeWriter writer = new Vintasoft.Barcode.BarcodeWriter())
{
writer.Settings.Barcode = barcodeType;
writer.Settings.Value = value;
// generate structure of 1D linear barcode
Vintasoft.Barcode.BarcodeStructure.LinearBarcodeStructure barcode =
(Vintasoft.Barcode.BarcodeStructure.LinearBarcodeStructure)writer.GetBarcodeStructure();
// get information about bars of 1D linear barcode
Vintasoft.Barcode.BarcodeStructure.BarcodeBarElement[] bars = barcode.GetBars();
// copy bar widths to an array
int[] result = new int[bars.Length];
for (int i = 0; i < bars.Length; i++)
result[i] = bars[i].Width;
return result;
}
}
Inheritance Hierarchy
Requirements
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also