←Select platform

BarcodeAlignment Enumeration

Summary
Horizontal or vertical alignment to use when writing barcodes.
Syntax
C#
Objective-C
C++/CLI
Java
Python
[SerializableAttribute()] 
public enum BarcodeAlignment   
typedef NS_ENUM(NSInteger, LTBarcodeAlignment) { 
 LTBarcodeAlignmentNear,  
 LTBarcodeAlignmentCenter,  
 LTBarcodeAlignmentFar 
}; 
public enum BarcodeAlignment 
[SerializableAttribute()] 
public enum class BarcodeAlignment   
class BarcodeAlignment(Enum): 
   Near = 0 
   Center = 1 
   Far = 2 
Members
ValueMemberDescription
0Near

Aligns the barcode to the near edge of BarcodeData.Bounds. This is the left edge (LeadRect.Left) when this is a horizontal alignment or the top edge (LeadRect.Top) when this is a vertical alignment.

The barcode actual width or height is not used.

1Center

Aligns the barcode to the center BarcodeData.Bounds. This is horizontal center (LeadRect.Left + (LeadRect.Width - "barcodeWidth") / 2) when this is a horizontal alignment or the vertical center (LeadRect.Top + (LeadRect.Height - "barcodeHeight") / 2) when this is a vertical alignment.

2Far

Aligns the barcode to the far edge of BarcodeData.Bounds. This is the left edge (LeadRect.Right - "barcodeWidth") if this is a horizontal alignment or the top edge (LeadRect.Bottom - "barcodeHeight") if this is a vertical alignment.

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 is used, an alignment value can set to determine whether the result 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.

Alignment is only supported by 2D symbologies (Datamatrix, MicroPDF417, PDF417 and QR). BarcodeAlignment is used as the type for the following properties:

Note that the default values for all these properties is BarcodeAlignment.Near.

Example

This example uses BarcodeAlignment to write a QR barcode at the 9 locations that can be set by changing the alignment. These locations are top/left, top/center, top/right, center/left, center/center, center/right, bottom/left, bottom/center and bottom/right.

C#
Java
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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.barcode.*; 
import leadtools.codecs.*; 
 
 
public void barcodeAlignmentExample(){ 
   BarcodeEngine engine = new BarcodeEngine(); 
   BarcodeWriter writer = engine.getWriter(); 
 
   // Create the QR barcode 
   BarcodeData barcode = BarcodeData.createDefaultBarcodeData(BarcodeSymbology.QR); 
 
   // Create the image (8.5 by 11 inches at 300 DPI) 
   int resolution = 300; 
   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.setBounds(new LeadRect(0, 0, image.getImageWidth(), image.getHeight())); 
 
   BarcodeWriteOptions options = (QRBarcodeWriteOptions)writer.getDefaultOptions(BarcodeSymbology.QR); 
 
   // 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 }; 
 
   for (BarcodeAlignment verticalAlignment : verticalAlignments){ 
      for (BarcodeAlignment horizontalAlignment : horizontalAlignments){ 
         // Write the barcode using these alignments 
         horizontalAlignment = verticalAlignment; 
         verticalAlignment = horizontalAlignment; 
         writer.writeBarcode(image, barcode, options); 
      } 
   } 
       
   // The image now have 9 barcodes 
 
   // Save the image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.save(image, "Result.jpg", RasterImageFormat.JPEG, 0); 
 
   assertTrue("Image unsuccessfully saved", (new File("Result.jpg")).exists()); 
   System.out.printf("Image loaded and saved to %s%n", new File("Result.jpg")); 
       
   image.dispose();; 
} 
Requirements

Target Platforms

See Also

Reference

Leadtools.Barcode Namespace

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

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