Barcode-Lib4J requires Java 11+

Java Class «TwoDSymbol»

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

public class TwoDSymbol extends Object
Drawable 2D code symbol that uses Graphics2D for rendering.

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

  • 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.

      For an explanation of what quiet zones are and the default quiet zone sizes for each 2D code type, see TwoDType.getDefaultQuietZone().

      Parameters:
      bitMatrix - the binary representation of the 2D code
      quietZoneSize - the size of the quiet zone to be appended around the 2D code
      Throws:
      NullPointerException - if the provided bit matrix is null
      IllegalArgumentException - if the specified quiet zone size is negative
  • 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