←Select platform

HorizontalAlignment Property

Summary
Gets or sets a value indicating the horizontal alignment to use when fitting this barcode inside the destination bounds.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public BarcodeAlignment HorizontalAlignment { get; set; } 
@property (nonatomic, assign) LTBarcodeAlignment horizontalAlignment; 
public BarcodeAlignment getHorizontalAlignment() 
public void setHorizontalAlignment(BarcodeAlignment value) 
public: 
property BarcodeAlignment HorizontalAlignment { 
   BarcodeAlignment get(); 
   void set (    BarcodeAlignment ); 
} 
HorizontalAlignment # get and set (PDF417BarcodeWriteOptions) 

Property Value

A BarcodeAlignment enumeration member that indicating the horizontal alignment to use when fitting this barcode inside the destination bounds. Default value is BarcodeAlignment.Near.

Remarks

When writing barcodes, the BarcodeWriter object may not use all the area defined by the output rectangle (BarcodeData.Bounds) since not all sizes can be used when writing a barcode and the value of the width and height of the bounds can have a special meaning. For more information, refer to Writing Barcodes - Bounds and XModule.

In cases where not all of the bounds are used, an alignment value can be set to determine whether the resulting barcode is left, top, right, bottom or center aligned to the rectangle. For these, you can use the BarcodeAlignment enumeration to control how the barcode is written.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
public void BarcodeAlignment_Example() 
{ 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.tif"); 
 
   BarcodeEngine engine = new BarcodeEngine(); 
   BarcodeWriter writer = engine.Writer; 
 
   // Create the QR barcode 
   BarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR); 
 
   // Create the image (8.5 by 11 inches at 300 DPI) 
   int resolution = 300; 
   using (RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))) 
   { 
      // We will control the position by alignment, so set the barcode bound to be the whole image 
      barcode.Bounds = new LeadRect(0, 0, image.ImageWidth, image.ImageHeight); 
 
      QRBarcodeWriteOptions options = writer.GetDefaultOptions(BarcodeSymbology.QR) as QRBarcodeWriteOptions; 
 
      // Let the engine determine the size of the barcode using X Module (default behavior) 
 
      // Use these alignments 
      BarcodeAlignment[] verticalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far }; 
      BarcodeAlignment[] horizontalAlignments = { BarcodeAlignment.Near, BarcodeAlignment.Center, BarcodeAlignment.Far }; 
 
      foreach (BarcodeAlignment verticalAlignment in verticalAlignments) 
      { 
         foreach (BarcodeAlignment horizontalAlignment in horizontalAlignments) 
         { 
            // Write the barcode using these alignments 
            options.HorizontalAlignment = verticalAlignment; 
            options.VerticalAlignment = horizontalAlignment; 
            writer.WriteBarcode(image, barcode, options); 
         } 
      } 
 
      // The image now have 9 barcodes 
 
      // Save the image 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools.Barcode Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.