Core barcode encoding/decoding library supporting 17 formats including QR Code, Data Matrix, Aztec, PDF 417, and various 1D barcodes
—
Complete Aztec Code 2D barcode encoding and decoding support. Aztec codes are square 2D matrix symbology with variable capacity (up to 3,832 numeric characters) and built-in error correction. A distinctive feature is the central bull's-eye finder pattern, and no quiet zone is required, making Aztec ideal for mobile tickets, transportation passes, and space-constrained applications.
Reader implementation for detecting and decoding Aztec barcodes from binary bitmap images. Supports both compact and full-range Aztec codes with automatic layer detection.
/**
* Reader implementation for Aztec Code 2D barcodes.
* Locates and decodes Aztec codes using the central bull's-eye finder pattern.
* Supports both compact (up to 4 layers) and full-range (up to 32 layers) variants.
*/
public class AztecReader implements Reader {
/**
* Creates a new Aztec reader.
*/
public AztecReader();
/**
* Locates and decodes an Aztec code in an image.
*
* @param image Binary bitmap representation of the image
* @return Result containing decoded text and metadata
* @throws NotFoundException If an Aztec code cannot be found in the image
* @throws FormatException If an Aztec code cannot be decoded
*/
@Override
public Result decode(BinaryBitmap image) throws NotFoundException, FormatException;
/**
* Locates and decodes an Aztec code in an image with configuration hints.
*
* @param image Binary bitmap representation of the image
* @param hints Map of DecodeHintType to configuration values
* - CHARACTER_SET (String): Expected character encoding
* - TRY_HARDER (Boolean): Spend more time for better accuracy
* @return Result containing decoded text and metadata
* @throws NotFoundException If an Aztec code cannot be found in the image
* @throws FormatException If an Aztec code cannot be decoded
*/
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException, FormatException;
/**
* Resets any internal state. Should be called between decoding attempts.
*/
@Override
public void reset();
}Usage Example:
import com.google.zxing.*;
import com.google.zxing.common.*;
import com.google.zxing.aztec.*;
import java.util.*;
// Create luminance source from image pixels
int[] pixels = ...; // RGB int array
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
// Decode Aztec code
Reader reader = new AztecReader();
Result result = reader.decode(bitmap);
// Access decoded data
String text = result.getText();
byte[] rawBytes = result.getRawBytes();
ResultPoint[] corners = result.getResultPoints();
// Access metadata
Map<ResultMetadataType, Object> metadata = result.getResultMetadata();
Integer errorsCorrected = (Integer) metadata.get(ResultMetadataType.ERRORS_CORRECTED);Writer implementation for encoding Aztec barcodes. Generates a BitMatrix representation with automatic or manual layer selection and configurable error correction.
/**
* Writer implementation for Aztec Code 2D barcodes.
* Encodes text into Aztec BitMatrix with automatic layer selection
* or manual layer specification.
*/
public final class AztecWriter implements Writer {
/**
* Creates a new Aztec writer.
*/
public AztecWriter();
/**
* Encodes contents into an Aztec BitMatrix with default settings.
* Uses automatic layer selection and 33% error correction.
*
* @param contents String content to encode
* @param format Must be BarcodeFormat.AZTEC
* @param width Preferred width in pixels
* @param height Preferred height in pixels
* @return BitMatrix representation of the Aztec code
* @throws WriterException If encoding fails
* @throws IllegalArgumentException If format is not AZTEC
*/
@Override
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height)
throws WriterException;
/**
* Encodes contents into an Aztec BitMatrix with configuration hints.
*
* @param contents String content to encode
* @param format Must be BarcodeFormat.AZTEC
* @param width Preferred width in pixels
* @param height Preferred height in pixels
* @param hints Map of EncodeHintType to configuration values
* - ERROR_CORRECTION (Integer): Error correction percentage (default: 33)
* - AZTEC_LAYERS (Integer): Specific layer count (negative for compact)
* Compact: -1 to -4 (1-4 layers)
* Full-range: 1 to 32 (1-32 layers)
* 0 or omitted: Automatic selection
* - CHARACTER_SET (String): Character encoding (e.g., "UTF-8")
* @return BitMatrix representation of the Aztec code
* @throws WriterException If encoding fails
* @throws IllegalArgumentException If parameters are invalid
*/
@Override
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height,
Map<EncodeHintType,?> hints) throws WriterException;
}Usage Example:
import com.google.zxing.*;
import com.google.zxing.common.*;
import com.google.zxing.aztec.*;
import java.util.*;
// Encode with default settings (automatic layer selection, 33% EC)
Writer writer = new AztecWriter();
BitMatrix matrix = writer.encode(
"https://example.com",
BarcodeFormat.AZTEC,
200,
200
);
// Encode with high error correction (50%)
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.ERROR_CORRECTION, 50);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix matrix2 = writer.encode(
"Important ticket data",
BarcodeFormat.AZTEC,
300,
300,
hints
);
// Force compact mode with 2 layers
hints.clear();
hints.put(EncodeHintType.AZTEC_LAYERS, -2); // Negative for compact
BitMatrix compact = writer.encode(
"Small data",
BarcodeFormat.AZTEC,
150,
150,
hints
);
// Force full-range mode with 10 layers
hints.clear();
hints.put(EncodeHintType.AZTEC_LAYERS, 10); // Positive for full-range
BitMatrix fullRange = writer.encode(
"Larger data content here...",
BarcodeFormat.AZTEC,
400,
400,
hints
);
// Convert BitMatrix to image pixels
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pixels[y * width + x] = matrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF;
}
}Compact Aztec:
Full-Range Aztec:
Unlike most 2D barcodes, Aztec codes do not require a quiet zone (white border), making them ideal for:
| Layers | Size | Numeric | Alphanumeric | Binary | EC % |
|---|---|---|---|---|---|
| 1 | 15x15 | 13 | 9 | 6 | 23% |
| 2 | 19x19 | 40 | 27 | 19 | 23% |
| 3 | 23x23 | 70 | 48 | 33 | 25% |
| 4 | 27x27 | 110 | 75 | 53 | 25% |
| Layers | Size | Numeric | Alphanumeric | Binary | EC % |
|---|---|---|---|---|---|
| 1 | 19x19 | 20 | 14 | 9 | 23% |
| 5 | 35x35 | 230 | 157 | 111 | 23% |
| 10 | 55x55 | 732 | 501 | 355 | 23% |
| 15 | 75x75 | 1532 | 1048 | 743 | 23% |
| 20 | 95x95 | 2492 | 1704 | 1208 | 23% |
| 25 | 115x115 | 3422 | 2341 | 1659 | 25% |
| 32 | 151x151 | 3832 | 2622 | 1857 | 25% |
Aztec uses Reed-Solomon error correction with configurable levels:
Default: 33%
Low: 23%
High: 50%+
// Low error correction (23%) - maximum capacity
hints.put(EncodeHintType.ERROR_CORRECTION, 23);
// Default error correction (33%)
hints.put(EncodeHintType.ERROR_CORRECTION, 33);
// High error correction (50%)
hints.put(EncodeHintType.ERROR_CORRECTION, 50);Let the encoder select the optimal layer count:
// Omit AZTEC_LAYERS or set to 0
BitMatrix matrix = writer.encode("Data", BarcodeFormat.AZTEC, 200, 200);Force compact mode with specific layers (-1 to -4):
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.AZTEC_LAYERS, -1); // Compact, 1 layer (15x15)
hints.put(EncodeHintType.AZTEC_LAYERS, -2); // Compact, 2 layers (19x19)
hints.put(EncodeHintType.AZTEC_LAYERS, -3); // Compact, 3 layers (23x23)
hints.put(EncodeHintType.AZTEC_LAYERS, -4); // Compact, 4 layers (27x27)Force full-range mode with specific layers (1 to 32):
hints.put(EncodeHintType.AZTEC_LAYERS, 1); // Full-range, 1 layer (19x19)
hints.put(EncodeHintType.AZTEC_LAYERS, 10); // Full-range, 10 layers (55x55)
hints.put(EncodeHintType.AZTEC_LAYERS, 32); // Full-range, 32 layers (151x151)Symbol Size Selection:
Error Correction:
No Quiet Zone Advantage:
Application Guidelines:
Quality Considerations:
Advanced Aztec Code encoder providing direct access to encoding operations without using the Writer interface. Useful for custom encoding workflows and accessing intermediate encoding results.
/**
* Aztec Code encoder with static methods for direct encoding.
* Provides fine-grained control over encoding parameters.
*/
public final class Encoder {
/**
* Default error correction percentage (33%).
*/
public static final int DEFAULT_EC_PERCENT = 33;
/**
* Default layer selection (0 = automatic).
*/
public static final int DEFAULT_AZTEC_LAYERS = 0;
/**
* Encodes string content as Aztec using default settings.
* Uses ISO-8859-1 encoding, 33% error correction, automatic layers.
*
* @param data Input string (must be ISO-8859-1 encodable)
* @return AztecCode object containing encoded matrix and metadata
*/
public static AztecCode encode(String data);
/**
* Encodes string content with custom error correction and layers.
*
* @param data Input string (must be ISO-8859-1 encodable)
* @param minECCPercent Error correction percentage (23-90, recommended: 23% + 3 words minimum)
* @param userSpecifiedLayers Layer specification:
* 0 = automatic (recommended)
* -1 to -4 = compact mode with specified layers
* 1 to 32 = full-range mode with specified layers
* @return AztecCode object containing encoded matrix and metadata
*/
public static AztecCode encode(String data, int minECCPercent, int userSpecifiedLayers);
/**
* Encodes string content with custom charset (adds ECI indicator).
*
* @param data Input string
* @param minECCPercent Error correction percentage
* @param userSpecifiedLayers Layer specification (0 for automatic)
* @param charset Character set for encoding (null for ISO-8859-1)
* @return AztecCode object containing encoded matrix and metadata
*/
public static AztecCode encode(String data, int minECCPercent, int userSpecifiedLayers, Charset charset);
/**
* Encodes binary data as Aztec using default settings.
*
* @param data Binary data bytes
* @return AztecCode object containing encoded matrix and metadata
*/
public static AztecCode encode(byte[] data);
/**
* Encodes binary data with custom error correction and layers.
*
* @param data Binary data bytes
* @param minECCPercent Error correction percentage
* @param userSpecifiedLayers Layer specification (0 for automatic)
* @return AztecCode object containing encoded matrix and metadata
*/
public static AztecCode encode(byte[] data, int minECCPercent, int userSpecifiedLayers);
/**
* Encodes binary data with custom charset ECI marker.
*
* @param data Binary data bytes
* @param minECCPercent Error correction percentage
* @param userSpecifiedLayers Layer specification (0 for automatic)
* @param charset Character set to mark with ECI (null for default)
* @return AztecCode object containing encoded matrix and metadata
*/
public static AztecCode encode(byte[] data, int minECCPercent, int userSpecifiedLayers, Charset charset);
}Usage Example:
import com.google.zxing.aztec.encoder.*;
import java.nio.charset.StandardCharsets;
// Simple encoding with defaults
AztecCode aztec = Encoder.encode("Hello, World!");
// Access encoded structure
BitMatrix matrix = aztec.getMatrix();
int layers = aztec.getLayers();
boolean compact = aztec.isCompact();
int size = aztec.getSize();
System.out.println("Aztec " + (compact ? "Compact" : "Full-range"));
System.out.println("Layers: " + layers);
System.out.println("Size: " + size + "x" + size);
// Custom error correction (50%)
AztecCode highEC = Encoder.encode("Important data", 50, 0);
// Force compact mode with 2 layers
AztecCode compactAztec = Encoder.encode("Ticket#12345", 33, -2);
// Force full-range mode with 10 layers
AztecCode fullRange = Encoder.encode("Large data...", 23, 10);
// UTF-8 encoding with ECI
AztecCode utf8Aztec = Encoder.encode(
"Hello 世界",
33,
0,
StandardCharsets.UTF_8
);
// Binary data encoding
byte[] binaryData = new byte[]{0x01, 0x02, 0x03, 0x04};
AztecCode binaryAztec = Encoder.encode(binaryData, 33, 0);Represents an encoded Aztec Code with access to the matrix and encoding parameters. Used as the output of the Encoder class, providing programmatic access to the encoded structure.
/**
* Represents an encoded Aztec Code structure with matrix and metadata.
* Provides access to encoding parameters and the encoded bit matrix.
*/
public final class AztecCode {
/**
* Checks if the code is compact mode.
*
* @return true if compact (1-4 layers), false if full-range (1-32 layers)
*/
public boolean isCompact();
/**
* Sets compact mode flag.
*
* @param compact true for compact mode, false for full-range
*/
public void setCompact(boolean compact);
/**
* Gets the symbol size in pixels (width and height).
*
* @return Size in pixels
*/
public int getSize();
/**
* Sets the symbol size.
*
* @param size Size in pixels
*/
public void setSize(int size);
/**
* Gets the number of layers (rings around center).
*
* @return Number of layers (1-4 for compact, 1-32 for full-range)
*/
public int getLayers();
/**
* Sets the number of layers.
*
* @param layers Number of layers
*/
public void setLayers(int layers);
/**
* Gets the number of data codewords.
*
* @return Number of data codewords (excluding error correction)
*/
public int getCodeWords();
/**
* Sets the number of data codewords.
*
* @param codeWords Number of data codewords
*/
public void setCodeWords(int codeWords);
/**
* Gets the encoded symbol matrix.
*
* @return BitMatrix containing the complete Aztec Code
*/
public BitMatrix getMatrix();
/**
* Sets the encoded symbol matrix.
*
* @param matrix BitMatrix to set
*/
public void setMatrix(BitMatrix matrix);
}Usage Example:
import com.google.zxing.aztec.encoder.*;
import com.google.zxing.common.*;
// Encode and inspect structure
AztecCode aztec = Encoder.encode("Sample data", 33, 0);
// Check encoding parameters
if (aztec.isCompact()) {
System.out.println("Compact Aztec with " + aztec.getLayers() + " layers");
System.out.println("Size: " + aztec.getSize() + "x" + aztec.getSize() + " modules");
} else {
System.out.println("Full-range Aztec with " + aztec.getLayers() + " layers");
System.out.println("Size: " + aztec.getSize() + "x" + aztec.getSize() + " modules");
}
System.out.println("Data codewords: " + aztec.getCodeWords());
// Access matrix
BitMatrix matrix = aztec.getMatrix();
int width = matrix.getWidth();
int height = matrix.getHeight();
// Convert to image
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
boolean isBlack = matrix.get(x, y);
// Render pixel
}
}