Instances can be obtained by calling the buildSymbol method of the
TwoDCode class.
-
Constructor Summary
ConstructorsConstructorDescriptionTwoDSymbol(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 TypeMethodDescriptionvoiddraw(Graphics2D g2d, double x, double y, double w, double h) Draws the 2D code symbol.voiddraw(Graphics2D g2d, double x, double y, double w, double h, double dotSize) Draws the 2D code symbol.voiddraw(Graphics2D g2d, double x, double y, double w, double h, double dotSize, double moduleSize, double horBarWidthCorrection, double verBarWidthCorrection) Draws the 2D code symbol.
-
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 codequietZoneSize- the size of the quiet zone to be appended around the 2D code- Throws:
NullPointerException- if the provided bit matrix isnullIllegalArgumentException- 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
dotSizecalculation. 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, ifdotSizeis greater than 0.0, the module size is adjusted to ensure that each module has a size that is a multiple ofdotSize.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 onx- the x-coordinate of the top-left corner of the bounding boxy- the y-coordinate of the top-left corner of the bounding boxw- the width of the bounding boxh- the height of the bounding boxdotSize- the size of a single point on the output medium or 0.0moduleSize- the size of each module (bit) of the 2D code symbol or 0.0horBarWidthCorrection- horizontal bar width correction factor or 0.0verBarWidthCorrection- vertical bar width correction factor or 0.0
-
draw
Draws the 2D code symbol.This method variant with a shortened parameter list only considers
dotSizefrom 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
drawmethod for a detailed parameter description.- Parameters:
g2d- the graphics context to draw onx- the x-coordinate of the top-left corner of the bounding boxy- the y-coordinate of the top-left corner of the bounding boxw- the width of the bounding boxh- the height of the bounding boxdotSize- the size of a single point on the output medium or 0.0
-
draw
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
drawmethod for a detailed parameter description.- Parameters:
g2d- the graphics context to draw onx- the x-coordinate of the top-left corner of the bounding boxy- the y-coordinate of the top-left corner of the bounding boxw- the width of the bounding boxh- the height of the bounding box
-