public static BarcodeData CreateDefaultBarcodeData(BarcodeSymbology symbology)
Public Shared Function CreateDefaultBarcodeData( _ByVal symbology As BarcodeSymbology _) As BarcodeData
+ (nullable LTBarcodeData *)createDefaultBarcodeData:(LTBarcodeSymbology)symbology public static BarcodeData createDefaultBarcodeData(BarcodeSymbology symbology) public:static BarcodeData^ CreateDefaultBarcodeData(BarcodeSymbology symbology)
symbology
Barcode symbology.
An instance of BarcodeData or one of its derived classes filled with default and legal values of the symbology that can be used directly with BarcodeWriter.WriteBarcode.
When writing barcodes, you must fill in a member of BarcodeData with legal values for the symbology based on the standard. This method can be used to quickly create a valid BarcodeData instance for the specified symbology and might be helpful for debugging.
The C# and VB Barcode demos use this method to obtain an initial BarcodeData for a symbology.
Note that if the symbology supports derived BarcodeData types, then an instance of the derived class will be returned instead. This includes DatamatrixBarcodeData, MicroPDF417BarcodeData, PDF417BarcodeData and QRBarcodeData for BarcodeSymbology.Datamatrix, BarcodeSymbology.MicroPDF417, BarcodeSymbology.PDF417 and BarcodeSymbology.QR respectively.
The GetBarcodeDataType method returns the Type of the derived class associated with a specified symbology or the BarcodeData type when the symbology does not have a specialized data class.
This example writes all the supported barcodes with LEADTOOLS using their default values.
using Leadtools;using Leadtools.Codecs;using Leadtools.Barcode;using Leadtools.ImageProcessing;public void BarcodeData_CreateDefaultBarcodeDataExample(){// 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(LeadRect.Empty, resolution, resolution, data, null);// Create an image to write the data toLeadRect pixels = data.Bounds;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:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.BarcodeImports Leadtools.ImageProcessingPublic Sub BarcodeData_CreateDefaultBarcodeDataExample()' 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(LeadRect.Empty, resolution, resolution, data, Nothing)' Create an image to write the data toDim pixels As LeadRect = data.BoundsUsing 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:\LEADTOOLS21\Resources\Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
