Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class BarcodeImage
- Object
- 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.
Fields
public static final int CODE_128 = 0 | Code 128, switching between code sets A, B and C to keep the symbol short. |
public static final int EAN_13 = 1 | EAN-13: 12 digits, or 13 with a correct check digit. |
public static final int EAN_8 = 2 | EAN-8: 7 digits, or 8 with a correct check digit. |
public static final int UPC_A = 3 | UPC-A: 11 digits, or 12 with a correct check digit. |
public static final int CODE_39 = 4 | Code 39: digits, upper case letters, space and - . $ / + %. |
public static final int ITF = 5 | Interleaved 2 of 5: an even number of digits. |
public static final int DATA_MATRIX = 6 | Data Matrix ECC 200, the smallest square symbol that fits the data. |
public static final int QR_CODE = 7 | QR code at the medium error correction level, through QrCode. |
public static final int PDF417 = 8 | PDF417, the stacked code on boarding passes and identity cards. |
public static final int AZTEC = 9 | Aztec, 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. |
Methods
public static boolean[][] encode(int format, String data) | Encodes data into its module grid, indexed [row][column], without a quiet zone. |
public static Image create(int format, String data, int width, int height) | Draws data black on white, centered in a width by height image. |
public static Image create(int format, String data, int width, int height, int dark, int light) | Like create(int, String, int, int) with ARGB colors. |
public static int checkDigit(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. |
public static int[] code128Codewords(String data) | The Code 128 symbol values for data: the start code, the data, the modulo 103 checksum and the stop code (106). |
Inherited methods
Field details
CODE_128
public static final int CODE_128 = 0Code 128, switching between code sets A, B and C to keep the symbol
short. Takes ASCII 0 to 127.
EAN_13
public static final int EAN_13 = 1EAN-13: 12 digits, or 13 with a correct check digit.
EAN_8
public static final int EAN_8 = 2EAN-8: 7 digits, or 8 with a correct check digit.
UPC_A
public static final int UPC_A = 3UPC-A: 11 digits, or 12 with a correct check digit.
CODE_39
public static final int CODE_39 = 4Code 39: digits, upper case letters, space and
- . $ / + %.ITF
public static final int ITF = 5Interleaved 2 of 5: an even number of digits.
DATA_MATRIX
public static final int DATA_MATRIX = 6Data Matrix ECC 200, the smallest square symbol that fits the data.
QR_CODE
public static final int QR_CODE = 7QR code at the medium error correction level, through
QrCode.PDF417
public static final int PDF417 = 8PDF417, 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 grid
encode(int, String) returns.AZTEC
public static final int AZTEC = 9Aztec, 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.
Method details
encode
public static boolean[][] encode(int format, String data)Encodes
data into its module grid, indexed [row][column], without a
quiet zone. A 1D format answers a single row.Parameters
formatint- one of the format constants, such as
CODE_128 dataString- the text to encode
Returns
the grid,
true for a dark modulecreate
public static Image create(int format, String data, int width, int height)Draws
data black on white, centered in a width by height image.
A 1D code fills the height; a 2D code stays square.Parameters
formatint- one of the format constants, such as
EAN_13 dataString- the text to encode
widthint- image width in pixels
heightint- image height in pixels
Returns
the barcode image
create
public static Image create(int format, String data, int width, int height, int dark, int light)Like
create(int, String, int, int) with ARGB colors. Keep the
contrast high and the dark modules darker than the ground.Parameters
formatint- one of the format constants
dataString- the text to encode
widthint- image width in pixels
heightint- image height in pixels
darkint- ARGB color of the dark modules
lightint- ARGB color of the ground
Returns
the barcode image
checkDigit
public static int checkDigit(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.
Parameters
digitsString- the data digits without a check digit
Returns
the check digit, 0 to 9
code128Codewords
public static int[] code128Codewords(String data)The Code 128 symbol values for
data: the start code, the data, the
modulo 103 checksum and the stop code (106).Parameters
dataString- ASCII 0 to 127
Returns
the symbol values, each 0 to 106