Main class for the LEADTOOLS support for writing barcodes.
public sealed class BarcodeWriter Public NotInheritable Class BarcodeWriter public sealed sealed class BarcodeWriter @interface LTBarcodeWriter : NSObject public class BarcodeWriter function Leadtools.Barcode.BarcodeWriter() public ref class BarcodeWriter sealed The BarcodeWriter class is used to write a barcode to an image. You cannot create an instance of BarcodeWriter directly, instead, you use the instance created for you inside BarcodeEngine and accessed through the BarcodeEngine.Writer property:
Dim engine As New BarcodeEngine()Dim writer As BarcodeWriter = engine.Writer' Use can use the writer now, for example, write a UPCA barcode to an image:Dim data As New BarcodeData(BarcodeSymbology.UPCA,"01234567890")data.Bounds = New LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel)writer.WriteBarcode(myImage, data, Nothing)
BarcodeEngine engine = new BarcodeEngine();BarcodeWriter writer = engine.Writer;// Use can use the writer now, for example, write a UPCA barcode to an image:BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA,"01234567890");data.Bounds = new LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel);writer.WriteBarcode(myImage, data, null);
Or you can use the BarcodeWriter directly through the BarcodeEngine.Writer property:
Dim engine As New BarcodeEngine()// Use the instance in BarcodeEngine directly, for example, write a UPCA barcode to an image:Dim data As New BarcodeData(BarcodeSymbology.UPCA,"01234567890")data.Bounds = New LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel)engine.Writer.WriteBarcode(myImage, data, Nothing)
BarcodeEngine engine = new BarcodeEngine();// Use the instance in BarcodeEngine directly, for example, write a UPCA barcode to an image:BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA,"01234567890");data.Bounds = new LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel);engine.Write.WriteBarcode(myImage, data, null);
This example creates a barcode for each symbology supported by LEADTOOLS. It will then save the barcodes as TIFF files.
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms;using Leadtools.Barcode;using Leadtools.ImageProcessing;public void BarcodeWriter_Example(){// Create a directory to store the images we will createstring outDir = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes");if (Directory.Exists(outDir)){Directory.Delete(outDir, true);}Directory.CreateDirectory(outDir);int resolution = 300;// Create a Barcode engineBarcodeEngine engine = new BarcodeEngine();// Get the Barcode writerBarcodeWriter 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 1DOneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions;oneDWriteOptions.UseXModule = true;// All GS1 Databar StackedGS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions;gs1DatabarStackedWriteOptions.UseXModule = true;// Patch CodePatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions;patchCodeWriteOptions.UseXModule = true;// All PostNet/PlanetPostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions;postNetPlanetWriteOptions.UseXModule = true;// We will use this object to save filesusing (RasterCodecs codecs = new RasterCodecs()){// Get all the available write symbologiesBarcodeSymbology[] symbologies = writer.GetAvailableSymbologies();foreach (BarcodeSymbology symbology in symbologies){Console.WriteLine("Processing {0}", symbology);// Create the default data for this symbologyBarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology);// Calculate its size with default optionswriter.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, null);// Create an image to write the data toLeadRect 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 optionswriter.WriteBarcode(image, data, null);// Save itstring 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";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.FormsImports Leadtools.BarcodeImports Leadtools.ImageProcessingPublic Sub BarcodeWriter_Example()' Create a directory to store the images we will createDim outDir As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes")If Directory.Exists(outDir) ThenDirectory.Delete(outDir, True)End IfDirectory.CreateDirectory(outDir)Dim resolution As Integer = 300' Create a Barcode engineDim engine As New BarcodeEngine()' Get the Barcode writerDim 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 1DDim oneDWriteOptions As OneDBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions)oneDWriteOptions.UseXModule = True' All GS1 Databar StackedDim gs1DatabarStackedWriteOptions As GS1DatabarStackedBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked), GS1DatabarStackedBarcodeWriteOptions)gs1DatabarStackedWriteOptions.UseXModule = True' Patch CodeDim patchCodeWriteOptions As PatchCodeBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.PatchCode), PatchCodeBarcodeWriteOptions)patchCodeWriteOptions.UseXModule = True' All PostNet/PlanetDim postNetPlanetWriteOptions As PostNetPlanetBarcodeWriteOptions = DirectCast(writer.GetDefaultOptions(BarcodeSymbology.PostNet), PostNetPlanetBarcodeWriteOptions)postNetPlanetWriteOptions.UseXModule = True' We will use this object to save filesUsing codecs As New RasterCodecs()' Get all the available write symbologiesDim symbologies() As BarcodeSymbology = writer.GetAvailableSymbologies()For Each symbology As BarcodeSymbology In symbologiesConsole.WriteLine("Processing {0}", symbology)' Create the default data for this symbologyDim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(symbology)' Calculate its size with default optionswriter.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, Nothing)' Create an image to write the data toDim 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 optionswriter.WriteBarcode(image, data, Nothing)' Save itDim outFileName As String = Path.Combine(outDir, symbology.ToString() + ".tif")codecs.Save(image, outFileName, RasterImageFormat.Tif, 1)End UsingNextEnd UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms;using Leadtools.Barcode;using Leadtools.ImageProcessing;using Leadtools.Examples;public void BarcodeWriter_Example(){int resolution = 300;// Create a Barcode engineBarcodeEngine engine = new BarcodeEngine();// Get the Barcode writerBarcodeWriter 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 1DOneDBarcodeWriteOptions oneDWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeWriteOptions;oneDWriteOptions.UseXModule = true;// All GS1 Databar StackedGS1DatabarStackedBarcodeWriteOptions gs1DatabarStackedWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked) as GS1DatabarStackedBarcodeWriteOptions;gs1DatabarStackedWriteOptions.UseXModule = true;// Patch CodePatchCodeBarcodeWriteOptions patchCodeWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PatchCode) as PatchCodeBarcodeWriteOptions;patchCodeWriteOptions.UseXModule = true;// All PostNet/PlanetPostNetPlanetBarcodeWriteOptions postNetPlanetWriteOptions = writer.GetDefaultOptions(BarcodeSymbology.PostNet) as PostNetPlanetBarcodeWriteOptions;postNetPlanetWriteOptions.UseXModule = true;// We will use this object to save filesRasterCodecs codecs = new RasterCodecs();// Get all the available write symbologiesBarcodeSymbology[] symbologies = writer.GetAvailableSymbologies();foreach (BarcodeSymbology symbology in symbologies){Console.WriteLine("Processing {0}", symbology);// Create the default data for this symbologyBarcodeData data = BarcodeData.CreateDefaultBarcodeData(symbology);// Calculate its size with default optionswriter.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, null);// Create an image to write the data toLeadRect 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 optionswriter.WriteBarcode(image, data, null);// Save itusing (SampleImageStream outputStream = new SampleImageStream(symbology + ".tif")){codecs.Save(image, outputStream, RasterImageFormat.Tif, 1);}}}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.FormsImports Leadtools.BarcodeImports Leadtools.ImageProcessingPublic Sub BarcodeWriter_Example()Dim resolution As Integer = 300' Create a Barcode engineDim engine As BarcodeEngine = New BarcodeEngine()' Get the Barcode writerDim 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 1DDim oneDWriteOptions As OneDBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeWriteOptions)oneDWriteOptions.UseXModule = True' All GS1 Databar StackedDim gs1DatabarStackedWriteOptions As GS1DatabarStackedBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.GS1DatabarStacked), GS1DatabarStackedBarcodeWriteOptions)gs1DatabarStackedWriteOptions.UseXModule = True' Patch CodeDim patchCodeWriteOptions As PatchCodeBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.PatchCode), PatchCodeBarcodeWriteOptions)patchCodeWriteOptions.UseXModule = True' All PostNet/PlanetDim postNetPlanetWriteOptions As PostNetPlanetBarcodeWriteOptions = TryCast(writer.GetDefaultOptions(BarcodeSymbology.PostNet), PostNetPlanetBarcodeWriteOptions)postNetPlanetWriteOptions.UseXModule = True' We will use this object to save filesDim codecs As RasterCodecs = New RasterCodecs()' Get all the available write symbologiesDim symbologies As BarcodeSymbology() = writer.GetAvailableSymbologies()For Each symbology As BarcodeSymbology In symbologiesConsole.WriteLine("Processing {0}", symbology)' Create the default data for this symbologyDim data As BarcodeData = BarcodeData.CreateDefaultBarcodeData(symbology)' Calculate its size with default optionswriter.CalculateBarcodeDataBounds(LogicalRectangle.Empty, resolution, resolution, data, Nothing)' Create an image to write the data toDim 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 optionswriter.WriteBarcode(image, data, Nothing)' Save itUsing outputStream As SampleImageStream = New SampleImageStream(symbology & ".tif")codecs.Save(image, outputStream, RasterImageFormat.Tif, 1)End UsingEnd UsingNext symbologyEnd Sub
Programming with LEADTOOLS Barcode
UPC / EAN Barcodes in LEADTOOLS
GS1 DataBar / RSS-14 Barcodes in LEADTOOLS
Code 128 Barcodes in LEADTOOLS
USPS and 4-State Barcodes in LEADTOOLS
MSI Barcodes (Pulse Width Modulated) in LEADTOOLS
Miscellaneous Barcodes in LEADTOOLS
Datamatrix Barcodes in LEADTOOLS
PDF417 and MicroPDF417 Barcodes in LEADTOOLS
|
Products |
Support |
Feedback: BarcodeWriter Class - Leadtools.Barcode |
Introduction |
Help Version 19.0.2017.6.21
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.