CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-google-zxing--core

Core barcode encoding/decoding library supporting 17 formats including QR Code, Data Matrix, Aztec, PDF 417, and various 1D barcodes

Pending
Overview
Eval results
Files

ZXing Core

ZXing (Zebra Crossing) Core is a comprehensive Java barcode library supporting 17 formats including QR Code, Data Matrix, Aztec, PDF 417, and various 1D barcodes. Zero external dependencies, designed for desktop, mobile, and web applications.

Package Information

  • Maven: com.google.zxing:core:3.5.4
  • Language: Java
  • Dependencies: None
<dependency>
  <groupId>com.google.zxing</groupId>
  <artifactId>core</artifactId>
  <version>3.5.4</version>
</dependency>

Quick Start

Decode a barcode:

import com.google.zxing.*;
import com.google.zxing.common.*;

// Convert image to luminance source
LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

// Decode
Reader reader = new MultiFormatReader();
Result result = reader.decode(bitmap);
String text = result.getText();

Encode a QR code:

import com.google.zxing.*;
import com.google.zxing.common.BitMatrix;

Writer writer = new MultiFormatWriter();
BitMatrix matrix = writer.encode("Hello", BarcodeFormat.QR_CODE, 300, 300);

Complete Quick Start Guide

Core Concepts

Supported Formats

2D Barcodes: QR Code, Data Matrix, Aztec, PDF417, MaxiCode
1D Barcodes: Code 39/93/128, EAN-8/13, UPC-A/E, ITF, Codabar, RSS

Architecture

Image → LuminanceSource → Binarizer → BinaryBitmap → Reader → Result
Data → Writer → BitMatrix → Image

Key Components:

  • Reader/Writer: Main interfaces for decode/encode
  • MultiFormatReader/Writer: Auto-detect format
  • BinaryBitmap: Binary image representation
  • Result: Decoded barcode data + metadata

Essential Classes

ClassPurposePackage
MultiFormatReaderDecode any formatcom.google.zxing
MultiFormatWriterEncode any formatcom.google.zxing
QRCodeReader/WriterQR Code specificcom.google.zxing.qrcode
RGBLuminanceSourceConvert RGB imagescom.google.zxing
HybridBinarizerAdaptive binarizationcom.google.zxing.common
BinaryBitmapBinary representationcom.google.zxing
ResultDecode resultcom.google.zxing
BitMatrixEncode resultcom.google.zxing.common

Common Use Cases

Mobile Scanning

// Camera preview → YUV luminance source
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(
    yuvData, width, height, 0, 0, width, height, false);

QR Code with Error Correction

Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");

Parse Structured Data

ParsedResult parsed = ResultParser.parseResult(result);
if (parsed.getType() == ParsedResultType.WIFI) {
    WifiParsedResult wifi = (WifiParsedResult) parsed;
    // Use wifi.getSsid(), wifi.getPassword(), etc.
}

Real-World Scenarios

Configuration

Decode Hints (Common)

  • POSSIBLE_FORMATS - Limit to specific formats (faster)
  • TRY_HARDER - More thorough scanning (slower)
  • CHARACTER_SET - Expected encoding (e.g., "UTF-8")
  • PURE_BARCODE - Clean image with no border (faster)

Encode Hints (Common)

  • ERROR_CORRECTION - Error correction level (format-specific)
  • CHARACTER_SET - Text encoding
  • MARGIN - Quiet zone size in pixels
  • QR_VERSION - Force specific QR version (1-40)

Complete Configuration Reference

Exception Handling

try {
    Result result = reader.decode(bitmap);
} catch (NotFoundException e) {
    // No barcode found (common during scanning)
} catch (ChecksumException e) {
    // Barcode damaged or corrupted
} catch (FormatException e) {
    // Invalid barcode structure
}

Exception Handling Guide

Package Structure

com.google.zxing
├── (root)              # Core interfaces: Reader, Writer, Result
├── common              # BitMatrix, Binarizer, utilities
├── qrcode              # QR Code implementation
├── datamatrix          # Data Matrix implementation
├── pdf417              # PDF417 implementation
├── aztec               # Aztec Code implementation
├── maxicode            # MaxiCode implementation
├── oned                # 1D barcode implementations
├── multi               # Multiple barcode detection
└── client.result       # Result parsing (WiFi, vCard, etc.)

Complete Package Reference

Format Quick Reference

FormatTypeCapacityUse Case
QR Code2D7,089 numericURLs, mobile, general
Data Matrix2D3,116 numericSmall items, electronics
PDF4172D1,850 alphanumericIDs, transportation
Aztec2D3,832 numericTickets, no quiet zone
Code 1281DVariableShipping, packaging
EAN-131D13 digitsRetail products
UPC-A1D12 digitsNorth America retail

API Reference

Core APIs

Format-Specific

Advanced Features

Guides

Best Practices

Performance

  • Use POSSIBLE_FORMATS hint to limit format detection
  • Use PlanarYUVLuminanceSource for camera data (fastest)
  • Don't use TRY_HARDER for real-time video scanning
  • Crop to region of interest before processing

Reliability

  • Use HybridBinarizer for varying lighting (recommended)
  • Set CHARACTER_SET to "UTF-8" for international text
  • Use error correction level M or H for QR codes
  • Test with actual scanners before production

Mobile Apps

  • Throttle frame processing (e.g., every 100ms)
  • Process frames asynchronously
  • Deduplicate results (same barcode scanned multiple times)
  • Reset reader between scans

Common Patterns

Mobile Scanner: Continuous camera scanning with throttling
Batch Processing: Extract all barcodes from documents
WiFi QR Generator: Generate WiFi connection QR codes
Product Scanner: Scan UPC/EAN with validation
Shipping Labels: Generate Code 128 barcodes

View All Patterns

Troubleshooting

NotFoundException - No barcode found:

  • Ensure image quality (not blurry)
  • Try TRY_HARDER hint
  • Check lighting conditions
  • Verify format is supported

Character encoding issues:

  • Always set CHARACTER_SET hint to "UTF-8"
  • Check source data encoding
  • Use StringUtils.guessEncoding() for detection

QR code too small:

  • Increase width/height parameters
  • Check MARGIN hint (default is 4 modules)
  • Ensure minimum 10 pixels per module

Resources

  • GitHub: zxing/zxing
  • Maven Central: com.google.zxing:core
  • License: Apache 2.0

Install with Tessl CLI

npx tessl i tessl/maven-com-google-zxing--core@3.5.1
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.google.zxing/core@3.5.x