Class BarcodeImage
Generates 1D and 2D barcodes in pure Java and draws them as an Image.
encode(int, String) returns the module grid, true for a dark module,
without a quiet zone. A 1D code is a grid of one row.
create(int, String, int, int) draws that grid centered in an image of
the requested size, with the quiet zone the format needs, at a whole number
of pixels per module so a scanner sees clean edges.
Image ean = BarcodeImage.create(BarcodeImage.EAN_13, "400638133393", 600, 200);
Image box = BarcodeImage.create(BarcodeImage.DATA_MATRIX, "PART-0042", 300, 300);
Form f = new Form("Labels", BoxLayout.y());
f.add(new Label(ean)).add(new Label(box));
f.show();
Invalid data, such as a letter in an EAN or a wrong check digit, throws
IllegalArgumentException.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAztec, the smallest compact or full symbol that fits the text as UTF-8 bytes, with about a third of the symbol spent on error correction.static final intCode 128, switching between code sets A, B and C to keep the symbol short.static final intCode 39: digits, upper case letters, space and- . $ / + %.static final intData Matrix ECC 200, the smallest square symbol that fits the data.static final intEAN-13: 12 digits, or 13 with a correct check digit.static final intEAN-8: 7 digits, or 8 with a correct check digit.static final intInterleaved 2 of 5: an even number of digits.static final intPDF417, the stacked code on boarding passes and identity cards.static final intQR code at the medium error correction level, throughQrCode.static final intUPC-A: 11 digits, or 12 with a correct check digit. -
Method Summary
Modifier and TypeMethodDescriptionstatic intcheckDigit(String digits) The modulo 10 check digit of EAN-13, EAN-8 and UPC-A: weight 3 on the rightmost data digit, alternating with 1 to the left.static int[]code128Codewords(String data) The Code 128 symbol values fordata: the start code, the data, the modulo 103 checksum and the stop code (106).static ImageDrawsdatablack on white, centered in awidthbyheightimage.static ImageLikecreate(int, String, int, int)with ARGB colors.static boolean[][]Encodesdatainto its module grid, indexed[row][column], without a quiet zone.
-
Field Details
-
CODE_128
public static final int CODE_128Code 128, switching between code sets A, B and C to keep the symbol short. Takes ASCII 0 to 127.- See Also:
-
EAN_13
public static final int EAN_13EAN-13: 12 digits, or 13 with a correct check digit.- See Also:
-
EAN_8
public static final int EAN_8EAN-8: 7 digits, or 8 with a correct check digit.- See Also:
-
UPC_A
public static final int UPC_AUPC-A: 11 digits, or 12 with a correct check digit.- See Also:
-
CODE_39
public static final int CODE_39Code 39: digits, upper case letters, space and- . $ / + %.- See Also:
-
ITF
public static final int ITFInterleaved 2 of 5: an even number of digits.- See Also:
-
DATA_MATRIX
public static final int DATA_MATRIXData Matrix ECC 200, the smallest square symbol that fits the data.- See Also:
-
QR_CODE
public static final int QR_CODEQR code at the medium error correction level, throughQrCode.- See Also:
-
PDF417
public static final int PDF417PDF417, the stacked code on boarding passes and identity cards. Text is encoded as UTF-8 bytes in byte compaction mode; each row is three modules tall in the gridencode(int, String)returns.- See Also:
-
AZTEC
public static final int AZTECAztec, the smallest compact or full symbol that fits the text as UTF-8 bytes, with about a third of the symbol spent on error correction.- See Also:
-
-
Method Details
-
encode
Encodes
datainto its module grid, indexed[row][column], without a quiet zone. A 1D format answers a single row.Parameters
-
format: one of the format constants, such asCODE_128 -
data: the text to encode
Returns
the grid,
truefor a dark module -
-
create
Draws
datablack on white, centered in awidthbyheightimage. A 1D code fills the height; a 2D code stays square.Parameters
-
format: one of the format constants, such asEAN_13 -
data: the text to encode -
width: image width in pixels -
height: image height in pixels
Returns
the barcode image
-
-
create
Like
create(int, String, int, int)with ARGB colors. Keep the contrast high and the dark modules darker than the ground.Parameters
-
format: one of the format constants -
data: the text to encode -
width: image width in pixels -
height: image height in pixels -
dark: ARGB color of the dark modules -
light: ARGB color of the ground
Returns
the barcode image
-
-
checkDigit
The modulo 10 check digit of EAN-13, EAN-8 and UPC-A: weight 3 on the rightmost data digit, alternating with 1 to the left.
Parameters
digits: the data digits without a check digit
Returns
the check digit, 0 to 9
-
code128Codewords
The Code 128 symbol values for
data: the start code, the data, the modulo 103 checksum and the stop code (106).Parameters
data: ASCII 0 to 127
Returns
the symbol values, each 0 to 106
-