Leadtools.Barcode Namespace : BarcodeWriteOptions Class |
[TypeConverterAttribute()] [SerializableAttribute()] public abstract class BarcodeWriteOptions : BarcodeOptions, System.ICloneable
'Declaration <TypeConverterAttribute()> <SerializableAttribute()> Public MustInherit Class BarcodeWriteOptions Inherits BarcodeOptions Implements System.ICloneable
'Usage Dim instance As BarcodeWriteOptions
public sealed class BarcodeWriteOptions : System.ICloneable
ObjectiveC Syntax
Java Syntax
function Leadtools.Barcode.BarcodeWriteOptions()
[TypeConverterAttribute()] [SerializableAttribute()] public ref class BarcodeWriteOptions abstract : public BarcodeOptions, System.ICloneable
Note: In LEADTOOLS for Windows Runtime, the equivalent to this class is the IBarcodeWriteOptions interface.
The BarcodeWriter class contains the BarcodeWriter.WriteBarcode method which is used to write a barcode to an image. You must create an instance of BarcodeWriter, fill its members with the barcode properties and pass it to this method.
The BarcodeWriteOptions class and its derived types is used to control the options used when writing a barcode using LEADTOOLS. You can set the options in two ways:
The BarcodeWriter class contains default options for each barcode symbology (or group of common symbologies). These options can be retrieved using the BarcodeWriter.GetDefaultOptions method passing the symbology of interest. You can then change members of the returned BarcodeWriteOptions (or after casting it to the appropriate derived class).
You can also create an instance of one of the derived BarcodeWriteOptions classes and use it directly in the BarcodeWriter.WriteBarcode method which accepts the options as an input parameter.
The BarcodeWriteOptions contains the following members and features:
Member | Description |
---|---|
BarcodeWriteOptions.ForeColor |
Controls the barcode foreground color (color of the bars or symbols) to use when writing a barcode to an image. |
BarcodeWriteOptions.BackColor |
Controls the barcode background color (color of the spaces) to use when writing a barcode to an image. |
BarcodeWriteOptions.Load and BarcodeWriteOptions.Save |
Can be used to save or load the options to/from an XML file or stream. |
BarcodeWriteOptions.GetSupportedSymbologies and BarcodeWriteOptions.IsSupportedSymbology |
Can be used to get all the BarcodeSymbology's supported by this BarcodeWriteOptions type or to check when a particular symbology is supported. |
BarcodeWriteOptions is an abstract class and cannot be created directly, instead create one of the these derived classes:
Write options class | Descriptions |
---|---|
OneDBarcodeWriteOptions |
Standard 1D linear barcode options. Used when writing any of the following symbologies: EAN13, EAN8, UPCA, UPCE, Code3Of9, Code128, CodeInterleaved2Of5, Codabar, UCCEAN128, Code93, EANEXT5, EANEXT2, MSI, Code11, CodeStandard2Of5, GS1Databar, GS1DatabarLimited or GS1DatabarExpanded |
GS1DatabarStackedBarcodeWriteOptions |
GS1 DataBar Stacked barcode options. Used when writing GS1DatabarStacked or GS1DatabarExpandedStacked symbologies |
FourStateBarcodeWriteOptions |
4-State barcode options. Used when writing AustralianPost4State, RoyalMail4State or USPS4State symbologies |
PostNetPlanetBarcodeWriteOptions |
POSTNET/Planet barcode options. Used when writing PostNet or Planet symbologies |
PatchCodeBarcodeWriteOptions |
Patch code barcode options. Used when writing PatchCode symbology. |
DatamatrixBarcodeWriteOptions |
Datamatrix barcode options. Used when writing Datamatrix symbology. |
MicroPDF417BarcodeWriteOptions |
Micro PDF417 barcode options. Used when writing MicroPDF417 symbology. |
PDF417BarcodeWriteOptions |
PDF417 barcode options. Used when writing PDF417 symbology. |
QRBarcodeWriteOptions |
QR barcode options. Used when writing QR symbology. |
Public Sub BarcodeWriteOptions_Example() ' Create a directory to store the images we will create Dim outDir As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes") If Directory.Exists(outDir) Then Directory.Delete(outDir, True) End If Directory.CreateDirectory(outDir) Dim resolution As Integer = 300 ' Create a Barcode engine Dim engine As New BarcodeEngine() ' Get the Barcode writer Dim writer As BarcodeWriter = engine.Writer ' All 1D options have the UseXModule set to false by default, we need to set it to true ' so we can calculate the default size. We will change the default options so we can ' pass null to CalculateBarcodeDataBounds and WriteBarcode below ' For all Standard 1D Dim oneDWriteOptions As OneDBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions) oneDWriteOptions.UseXModule = True ' All GS1 Databar Stacked Dim gs1DatabarStackedWriteOptions As GS1DatabarStackedBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked), GS1DatabarStackedBarcodeWriteOptions) gs1DatabarStackedWriteOptions.UseXModule = True ' Patch Code Dim patchCodeWriteOptions As PatchCodeBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.PatchCode), PatchCodeBarcodeWriteOptions) patchCodeWriteOptions.UseXModule = True ' All PostNet/Planet Dim postNetPlanetWriteOptions As PostNetPlanetBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.PostNet), PostNetPlanetBarcodeWriteOptions) postNetPlanetWriteOptions.UseXModule = True ' We will use this object to save files Using codecs As New RasterCodecs() ' Get all the available write symbologies Dim symbologies() As BarcodeSymbology = writer.GetAvailableSymbologies() For Each symbology As BarcodeSymbology In symbologies Console.WriteLine("Processing {0}", symbology) ' Create the default data for this symbology Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(symbology) ' Calculate its size with default options writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, Nothing) ' Create an image to write the data to 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)) ' Write the barcode with default options writer.WriteBarcode(image, data, Nothing) ' Save it Dim outFileName As String = Path.Combine(outDir, symbology.ToString() + ".tif") codecs.Save(image, outFileName, RasterImageFormat.Tif, 1) End Using Next End Using End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void BarcodeWriteOptions_Example() { // Create a directory to store the images we will create string outDir = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes"); if(Directory.Exists(outDir)) { Directory.Delete(outDir, true); } Directory.CreateDirectory(outDir); int resolution = 300; // Create a Barcode engine BarcodeEngine engine = new BarcodeEngine(); // Get the Barcode writer BarcodeWriter writer = engine.Writer; // All 1D options have the UseXModule set to false by default, we need to set it to true // so we can calculate the default size. We will change the default options so we can // pass null to CalculateBarcodeDataBounds and WriteBarcode below // For all Standard 1D OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; oneDWriteOptions.UseXModule = true; // All GS1 Databar Stacked GS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions; gs1DatabarStackedWriteOptions.UseXModule = true; // Patch Code PatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions; patchCodeWriteOptions.UseXModule = true; // All PostNet/Planet PostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions; postNetPlanetWriteOptions.UseXModule = true; // We will use this object to save files using(RasterCodecs codecs = new RasterCodecs()) { // Get all the available write symbologies BarcodeSymbology[] symbologies = writer.GetAvailableSymbologies(); foreach(BarcodeSymbology symbology in symbologies) { Console.WriteLine("Processing {0}", symbology); // Create the default data for this symbology BarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology); // Calculate its size with default options writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, null); // Create an image to write the data to LeadRect pixels = data.Bounds.ToRectangle(resolution, resolution); using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) { // Write the barcode with default options writer.WriteBarcode(image, data, null); // Save it string outFileName = Path.Combine(outDir, symbology + ".tif"); codecs.Save(image, outFileName, RasterImageFormat.Tif, 1); } } } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
[TestMethod] public async Task BarcodeWriteOptions_Example() { int resolution = 300; // Create a Barcode engine BarcodeEngine engine = new BarcodeEngine(); // Get the Barcode writer BarcodeWriter writer = engine.Writer; // All 1D options have the UseXModule set to false by default, we need to set it to true // so we can calculate the default size. We will change the default options so we can // pass null to CalculateBarcodeDataBounds and WriteBarcode below // For all Standard 1D OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; oneDWriteOptions.UseXModule = true; // All GS1 Databar Stacked GS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions; gs1DatabarStackedWriteOptions.UseXModule = true; // Patch Code PatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions; patchCodeWriteOptions.UseXModule = true; // All PostNet/Planet PostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions; postNetPlanetWriteOptions.UseXModule = true; // We will use this object to save files using(RasterCodecs codecs = new RasterCodecs()) { // Get all the available write symbologies BarcodeSymbology[] symbologies = writer.GetAvailableSymbologies(); foreach(BarcodeSymbology symbology in symbologies) { Debug.WriteLine("Processing {0}", symbology); // Create the default data for this symbology BarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology); // Calculate its size with default options writer.CalculateBarcodeDataBounds(LeadRectHelper.Empty, resolution, resolution, data, null); // Create an image to write the data to LeadRect pixels = data.Bounds; using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColorHelper.FromKnownColor(RasterKnownColor.White))) { // Write the barcode with default options writer.WriteBarcode(image, data, null); // Save it string outFileName = symbology.ToString() + ".tif"; StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(outFileName); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1); } } } }
public void BarcodeWriteOptions_Example() { int resolution = 300; // Create a Barcode engine BarcodeEngine engine = new BarcodeEngine(); // Get the Barcode writer BarcodeWriter writer = engine.Writer; // All 1D options have the UseXModule set to false by default, we need to set it to true // so we can calculate the default size. We will change the default options so we can // pass null to CalculateBarcodeDataBounds and WriteBarcode below // For all Standard 1D OneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions; oneDWriteOptions.UseXModule = true; // All GS1 Databar Stacked GS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions; gs1DatabarStackedWriteOptions.UseXModule = true; // Patch Code PatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions; patchCodeWriteOptions.UseXModule = true; // All PostNet/Planet PostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions; postNetPlanetWriteOptions.UseXModule = true; // We will use this object to save files RasterCodecs codecs = new RasterCodecs(); // Get all the available write symbologies BarcodeSymbology[] symbologies = writer.GetAvailableSymbologies(); foreach(BarcodeSymbology symbology in symbologies) { Console.WriteLine("Processing {0}", symbology); // Create the default data for this symbology BarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology); // Calculate its size with default options writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, null); // Create an image to write the data to LeadRect pixels = data.Bounds.ToRectangle(resolution, resolution); using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) { // Write the barcode with default options writer.WriteBarcode(image, data, null); // Save it using (SampleImageStream outputStream = new SampleImageStream(symbology + ".tif")) { codecs.Save(image, outputStream, RasterImageFormat.Tif, 1); } } } }
Public Sub BarcodeWriteOptions_Example() Dim resolution As Integer = 300 ' Create a Barcode engine Dim engine As BarcodeEngine = New BarcodeEngine() ' Get the Barcode writer Dim writer As BarcodeWriter = engine.Writer ' All 1D options have the UseXModule set to false by default, we need to set it to true ' so we can calculate the default size. We will change the default options so we can ' pass null to CalculateBarcodeDataBounds and WriteBarcode below ' For all Standard 1D Dim oneDWriteOptions As OneDBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions) oneDWriteOptions.UseXModule = True ' All GS1 Databar Stacked Dim gs1DatabarStackedWriteOptions As GS1DatabarStackedBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked), GS1DatabarStackedBarcodeWriteOptions) gs1DatabarStackedWriteOptions.UseXModule = True ' Patch Code Dim patchCodeWriteOptions As PatchCodeBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.PatchCode), PatchCodeBarcodeWriteOptions) patchCodeWriteOptions.UseXModule = True ' All PostNet/Planet Dim postNetPlanetWriteOptions As PostNetPlanetBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.PostNet), PostNetPlanetBarcodeWriteOptions) postNetPlanetWriteOptions.UseXModule = True ' We will use this object to save files Dim codecs As RasterCodecs = New RasterCodecs() ' Get all the available write symbologies Dim symbologies As BarcodeSymbology() = writer.GetAvailableSymbologies() For Each symbology As BarcodeSymbology In symbologies Console.WriteLine("Processing {0}", symbology) ' Create the default data for this symbology Dim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(symbology) ' Calculate its size with default options writer.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, Nothing) ' Create an image to write the data to 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)) ' Write the barcode with default options writer.WriteBarcode(image, data, Nothing) ' Save it Using outputStream As SampleImageStream = New SampleImageStream(symbology & ".tif") codecs.Save(image, outputStream, RasterImageFormat.Tif, 1) End Using End Using Next symbology End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
BarcodeWriteOptions Members
Leadtools.Barcode Namespace
OneDBarcodeWriteOptions Class
GS1DatabarStackedBarcodeWriteOptions Class
FourStateBarcodeWriteOptions Class
PostNetPlanetBarcodeWriteOptions Class
PatchCodeBarcodeWriteOptions Class
DatamatrixBarcodeWriteOptions Class
MicroPDF417BarcodeWriteOptions Class
PDF417BarcodeWriteOptions Class
QRBarcodeWriteOptions Class
BarcodeWriter Class
BarcodeSymbology Enumeration
BarcodeEngine Class
BarcodeWriter.WriteBarcode
Programming with LEADTOOLS Barcode
Supported Barcode Symbologies
Unlocking Barcode Support
Writing Barcodes Tutorial
Writing Barcodes - Bounds and XModule