Barcode-Lib4J requires Java 9+

Java Class «TwoDSymbol»

java.lang.Object
de.vwsoft.barcodelib4j.twod.TwoDSymbol

public class TwoDSymbol extends Object
Drawable 2D code symbol.

Instances can be obtained by calling the buildSymbol method of the TwoDCode class.

(Alternatively, you can use the built-in ZXing library directly to obtain a BitMatrix, which is required to create instances of this class. Please note that some 2D code implementations in the ZXing library may not support the EncodeHintType.MARGIN hint, resulting in no quiet zones appended to the resulting BitMatrix. In contrast, other implementations may have this property set to an unwanted default value. To work around this, you can generally set the MARGIN hint to zero and instead use the quiet zone parameter in the constructor of this class to append the needed quiet zone.)

  • Constructor Summary

    Constructors
    Constructor
    Description
    TwoDSymbol(de.vwsoft.barcodelib4j.twod.zxing.BitMatrix bitMatrix, int quietZoneSize)
    Constructs an instance using the binary representation (bit matrix) of a 2D code.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    draw(Graphics2D g2d, double x, double y, double w, double h)
    Draws the 2D code symbol.
    void
    draw(Graphics2D g2d, double x, double y, double w, double h, double dotSize)
    Draws the 2D code symbol.
    void
    draw(Graphics2D g2d, double x, double y, double w, double h, double dotSize, double moduleSize, double horBarWidthCorrection, double verBarWidthCorrection)
    Draws the 2D code symbol.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TwoDSymbol

      public TwoDSymbol(de.vwsoft.barcodelib4j.twod.zxing.BitMatrix bitMatrix, int quietZoneSize)
      Constructs an instance using the binary representation (bit matrix) of a 2D code.

      A quiet zone, measured in modules (individual elements of the code), determines the width of the blank space around the code. It's important to set an appropriate quiet zone to ensure proper scanning and decoding of the symbol. The required minimum values for the quiet zone are available for all supported 2D code types in the TwoDCode.ALL_QUIET_ZONES array.

      Parameters:
      bitMatrix - the binary representation of the 2D code
      quietZoneSize - the size of the quiet zone to be appended around the 2D code
  • Method Details

    • draw

      public void draw(Graphics2D g2d, double x, double y, double w, double h, double dotSize, double moduleSize, double horBarWidthCorrection, double verBarWidthCorrection)
      Draws the 2D code symbol.

      Special attention is paid to the quality and, consequently, the later readability of the resulting 2D code. This is mainly ensured by the following four parameters:

      dotSize - Specifies the size of a single point on the output medium, calculated from its resolution. For a printer, this should be the size of a dot, determined by the printer's resolution (DPI). For a bitmap image, it should be the "physical" size of a pixel, calculated from the pixel density (PPI). The value should be specified in the same unit as the other parameters. When using millimeters, for a resolution of 300 DPI/PPI, the formula would be: 25.4 / 300. When using inches: 1 / 300. This adjustment may be negligible in high-resolution output scenarios, where the value can be set to 0.0.

      Note: If the output medium has differing horizontal and vertical resolutions, use the smaller resolution for dotSize calculation. Example: For 300x600 DPI, use 300 DPI.

      moduleSize - Allows it to specify a fixed size of the modules (bits), that will affect the overall size of the 2D code symbol. If set to 0.0, the method will automatically calculate an appropriate module size based on the dimensions of the bounding box and the value of dotSize. In any case, if dotSize is greater than 0.0, the module size is adjusted to ensure that each module has a size that is a multiple of dotSize.

      hor- & verBarWidthCorrection - Adjusts the size of the modules (bits) of the 2D code symbol. A positive value increases the size of the modules, while a negative value reduces them. For example, in the case of a printer, where ink bleeding may occur, a negative value may be necessary to compensate for the ink bleeding and ensure accurate module size. Similarly, for output scenarios where undesirable effects don't occur, the value can be set to 0.0.

      Parameters:
      g2d - the graphics context to draw on
      x - the x-coordinate of the top-left corner of the bounding box
      y - the y-coordinate of the top-left corner of the bounding box
      w - the width of the bounding box
      h - the height of the bounding box
      dotSize - the size of a single point on the output medium or 0.0
      moduleSize - the size of each module (bit) of the 2D code symbol or 0.0
      horBarWidthCorrection - horizontal bar width correction factor or 0.0
      verBarWidthCorrection - vertical bar width correction factor or 0.0
    • draw

      public void draw(Graphics2D g2d, double x, double y, double w, double h, double dotSize)
      Draws the 2D code symbol.

      This method variant with a shortened parameter list only considers dotSize from the quality settings and uses 0.0 for the rest.

      These settings are typically suitable for printing on a thermal transfer printer, where the low resolution of the printer must be taken into account, and where no bar width correction is required for accurate printing.

      The settings are also well suited to exporting the 2D code as a bitmap image.

      Please refer to the main draw method for a detailed parameter description.

      Parameters:
      g2d - the graphics context to draw on
      x - the x-coordinate of the top-left corner of the bounding box
      y - the y-coordinate of the top-left corner of the bounding box
      w - the width of the bounding box
      h - the height of the bounding box
      dotSize - the size of a single point on the output medium or 0.0
    • draw

      public void draw(Graphics2D g2d, double x, double y, double w, double h)
      Draws the 2D code symbol.

      This method variant with a shortened parameter list does not consider any quality settings. It is typically suitable for printing on laser printers or exporting as vector graphics.

      Please refer to the main draw method for a detailed parameter description.

      Parameters:
      g2d - the graphics context to draw on
      x - the x-coordinate of the top-left corner of the bounding box
      y - the y-coordinate of the top-left corner of the bounding box
      w - the width of the bounding box
      h - the height of the bounding box