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

result-handling.mddocs/reference/

Result Handling

Classes for encapsulating barcode detection results, including decoded text, raw bytes, result points (corners/finder patterns), format information, and extensive metadata. Supports result point callbacks for visual feedback during decoding. The Result class is returned by all Reader implementations and contains comprehensive information about the detected barcode.

Capabilities

Result

Main result class encapsulating all information about a decoded barcode. Contains text, raw bytes, location points, format, and metadata.

/**
 * Encapsulates the result of decoding a barcode within an image.
 * Contains decoded text, raw bytes, location points, format, and metadata.
 */
public final class Result {
    /**
     * Creates a new barcode result.
     *
     * @param text Decoded text string
     * @param rawBytes Raw decoded bytes (may be null)
     * @param resultPoints Points of interest (corners, finder patterns, etc.)
     * @param format Detected barcode format
     */
    public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format);

    /**
     * Creates a result with timestamp.
     *
     * @param text Decoded text string
     * @param rawBytes Raw decoded bytes (may be null)
     * @param resultPoints Points of interest
     * @param format Detected barcode format
     * @param timestamp Time of decode in milliseconds since epoch
     */
    public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format, long timestamp);

    /**
     * Gets the decoded text.
     *
     * @return Decoded text string
     */
    public String getText();

    /**
     * Gets the raw decoded bytes.
     *
     * @return Raw bytes or null if not available
     */
    public byte[] getRawBytes();

    /**
     * Gets the number of valid bits in raw bytes.
     *
     * @return Number of bits (8 * bytes.length if not specified)
     */
    public int getNumBits();

    /**
     * Gets the result points (corners, finder patterns, etc.).
     *
     * @return Array of ResultPoint objects
     */
    public ResultPoint[] getResultPoints();

    /**
     * Gets the detected barcode format.
     *
     * @return BarcodeFormat enum value
     */
    public BarcodeFormat getBarcodeFormat();

    /**
     * Gets all result metadata.
     *
     * @return Map of ResultMetadataType to values, or null if no metadata
     */
    public Map<ResultMetadataType,Object> getResultMetadata();

    /**
     * Adds a single metadata entry.
     *
     * @param type Metadata type
     * @param value Metadata value
     */
    public void putMetadata(ResultMetadataType type, Object value);

    /**
     * Adds multiple metadata entries.
     *
     * @param metadata Map of metadata to add
     */
    public void putAllMetadata(Map<ResultMetadataType,Object> metadata);

    /**
     * Adds additional result points to the existing result points array.
     * Useful for supplementing results with additional location information.
     *
     * @param newPoints Additional points to add
     */
    public void addResultPoints(ResultPoint[] newPoints);

    /**
     * Gets the timestamp of when this result was decoded.
     *
     * @return Time in milliseconds since epoch
     */
    public long getTimestamp();

    /**
     * Returns string representation of the result.
     *
     * @return Decoded text
     */
    @Override
    public String toString();
}

Usage Example:

import com.google.zxing.*;
import java.util.Map;

// Decode barcode
Reader reader = new MultiFormatReader();
Result result = reader.decode(bitmap);

// Access basic information
String text = result.getText();
byte[] rawBytes = result.getRawBytes();
BarcodeFormat format = result.getBarcodeFormat();
ResultPoint[] points = result.getResultPoints();

// Access metadata
Map<ResultMetadataType, Object> metadata = result.getResultMetadata();
if (metadata != null) {
    String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
    Integer errorsCorrected = (Integer) metadata.get(ResultMetadataType.ERRORS_CORRECTED);
    Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION);

    System.out.println("Format: " + format);
    System.out.println("EC Level: " + ecLevel);
    System.out.println("Errors corrected: " + errorsCorrected);
    System.out.println("Orientation: " + orientation + " degrees");
}

// Get result points (corners/finder patterns)
for (int i = 0; i < points.length; i++) {
    System.out.println("Point " + i + ": (" + points[i].getX() + ", " + points[i].getY() + ")");
}

ResultPoint

Represents a point of interest in a barcode image, such as corners or finder pattern centers. Used for overlay visualization and geometric analysis.

/**
 * Encapsulates a point of interest in an image containing a barcode.
 * Typically represents corners, finder pattern centers, or alignment patterns.
 */
public class ResultPoint {
    /**
     * Creates a result point at specified coordinates.
     *
     * @param x X coordinate (pixels from left)
     * @param y Y coordinate (pixels from top)
     */
    public ResultPoint(float x, float y);

    /**
     * Gets the X coordinate.
     *
     * @return X coordinate in pixels
     */
    public final float getX();

    /**
     * Gets the Y coordinate.
     *
     * @return Y coordinate in pixels
     */
    public final float getY();

    /**
     * Calculates Euclidean distance between two points.
     *
     * @param pattern1 First point
     * @param pattern2 Second point
     * @return Distance in pixels
     */
    public static float distance(ResultPoint pattern1, ResultPoint pattern2);

    /**
     * Orders three pattern points by distance from fourth point.
     * Useful for identifying top-left, top-right, and bottom-left corners.
     *
     * @param patterns Array of exactly 3 ResultPoints to reorder in-place
     */
    public static void orderBestPatterns(ResultPoint[] patterns);

    /**
     * Calculates cross product of vectors AB and BC.
     *
     * @param pointA First point
     * @param pointB Center point
     * @param pointC Last point
     * @return Cross product (positive if counter-clockwise)
     */
    // Note: crossProductZ is not publicly accessible in ZXing Core 3.5.4
    // public static float crossProductZ(ResultPoint pointA, ResultPoint pointB, ResultPoint pointC);
}

Usage Example:

import com.google.zxing.ResultPoint;

// Get result points from decode
ResultPoint[] points = result.getResultPoints();

// Draw overlay on image
for (ResultPoint point : points) {
    int x = (int) point.getX();
    int y = (int) point.getY();
    // Draw circle or marker at (x, y)
}

// Calculate distances
if (points.length >= 2) {
    float distance = ResultPoint.distance(points[0], points[1]);
    System.out.println("Distance between first two points: " + distance);
}

ResultMetadataType

Enumeration of metadata keys that can be attached to a Result. Provides additional information beyond the decoded text.

/**
 * Enumeration of metadata types that can be attached to decode results.
 * Different barcode formats provide different metadata.
 */
public enum ResultMetadataType {
    /**
     * Orientation of barcode in image (Integer, degrees).
     * 0, 90, 180, or 270 degrees.
     */
    ORIENTATION,

    /**
     * List of byte segments (List<byte[]>).
     * Used for QR Code and other formats with multiple data segments.
     */
    BYTE_SEGMENTS,

    /**
     * Error correction level used (String).
     * Format-specific values (e.g., "L", "M", "Q", "H" for QR Code).
     */
    ERROR_CORRECTION_LEVEL,

    /**
     * Number of errors corrected during decoding (Integer).
     */
    ERRORS_CORRECTED,

    /**
     * Number of erasures corrected during decoding (Integer).
     */
    ERASURES_CORRECTED,

    /**
     * Issue number for periodicals (Integer).
     * Used with UPC/EAN barcodes.
     */
    ISSUE_NUMBER,

    /**
     * Suggested retail price (String).
     * Used with UPC/EAN barcodes.
     */
    SUGGESTED_PRICE,

    /**
     * Possible country of origin (String, ISO country code).
     * Deduced from EAN-13 prefix.
     */
    POSSIBLE_COUNTRY,

    /**
     * UPC/EAN extension value (String).
     * 2 or 5 digit extension data.
     */
    UPC_EAN_EXTENSION,

    /**
     * PDF417-specific metadata (PDF417ResultMetadata object).
     * Contains segment info, file ID, etc.
     */
    PDF417_EXTRA_METADATA,

    /**
     * Structured append sequence number (Integer).
     * Position in multi-barcode sequence (0-based).
     */
    STRUCTURED_APPEND_SEQUENCE,

    /**
     * Structured append parity data (Integer).
     * Used to validate multi-barcode sequences.
     */
    STRUCTURED_APPEND_PARITY,

    /**
     * Symbology identifier (String).
     * Standard identifier like "]Q1" for QR Code, "]d2" for Data Matrix.
     */
    SYMBOLOGY_IDENTIFIER
}

ResultPointCallback

Interface for receiving notifications during barcode detection. Useful for showing visual feedback as the decoder locates key points.

/**
 * Callback interface for result points found during decoding.
 * Implement this to receive notifications of finder patterns,
 * alignment patterns, and other points of interest as they are found.
 * Useful for showing real-time visual feedback during detection.
 */
public interface ResultPointCallback {
    /**
     * Called when a possible result point is found.
     *
     * @param point Location of the found point
     */
    void foundPossibleResultPoint(ResultPoint point);
}

Usage Example:

import com.google.zxing.*;
import java.util.*;

// Create callback to visualize detection
ResultPointCallback callback = new ResultPointCallback() {
    @Override
    public void foundPossibleResultPoint(ResultPoint point) {
        System.out.println("Found point at: (" + point.getX() + ", " + point.getY() + ")");
        // Update UI to show point location
    }
};

// Use callback during decoding
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, callback);

Reader reader = new MultiFormatReader();
Result result = reader.decode(bitmap, hints);

Dimension

Simple container for width and height dimensions. Used for size constraints in encoding.

/**
 * Simple container for width and height dimensions.
 */
public final class Dimension {
    /**
     * Creates a dimension.
     *
     * @param width Width value
     * @param height Height value
     */
    public Dimension(int width, int height);

    /**
     * Gets the width.
     *
     * @return Width value
     */
    public int getWidth();

    /**
     * Gets the height.
     *
     * @return Height value
     */
    public int getHeight();

    /**
     * Checks equality with another dimension.
     *
     * @param other Object to compare
     * @return true if dimensions are equal
     */
    @Override
    public boolean equals(Object other);

    /**
     * Gets hash code.
     *
     * @return Hash code value
     */
    @Override
    public int hashCode();

    /**
     * Gets string representation.
     *
     * @return String in format "widthxheight"
     */
    @Override
    public String toString();
}

Metadata by Format

QR Code Metadata

  • ERROR_CORRECTION_LEVEL: "L", "M", "Q", or "H"
  • ERRORS_CORRECTED: Number of errors fixed
  • BYTE_SEGMENTS: Raw data segments
  • STRUCTURED_APPEND_SEQUENCE: Multi-QR sequence number
  • STRUCTURED_APPEND_PARITY: Multi-QR parity
  • SYMBOLOGY_IDENTIFIER: "]Q1" through "]Q6"

Data Matrix Metadata

  • ERROR_CORRECTION_LEVEL: Error correction info
  • ERRORS_CORRECTED: Number of errors fixed
  • BYTE_SEGMENTS: Raw data segments
  • SYMBOLOGY_IDENTIFIER: "]d1" through "]d6"

PDF417 Metadata

  • ERROR_CORRECTION_LEVEL: EC level string
  • ERRORS_CORRECTED: Number of errors fixed
  • ERASURES_CORRECTED: Number of erasures fixed
  • PDF417_EXTRA_METADATA: Detailed PDF417 info
  • ORIENTATION: Barcode rotation (0/90/180/270)
  • SYMBOLOGY_IDENTIFIER: "]L0" through "]L7"

1D Barcode Metadata

  • ORIENTATION: Barcode rotation if detected
  • POSSIBLE_COUNTRY: Country from EAN-13 prefix
  • UPC_EAN_EXTENSION: Extension barcode data
  • ISSUE_NUMBER: Magazine/periodical issue
  • SUGGESTED_PRICE: Retail price from extension
  • SYMBOLOGY_IDENTIFIER: Format-specific identifier

Best Practices

Using Result Points:

  • Draw overlay graphics at result point locations for user feedback
  • Use points to calculate barcode orientation and perspective
  • QR Codes typically have 3-4 points (finder pattern corners)
  • 1D barcodes have 2 points (left and right edges)

Processing Metadata:

  • Always check if metadata map is null before accessing
  • Cast metadata values to appropriate types based on ResultMetadataType
  • Use ERROR_CORRECTION_LEVEL to assess decode confidence
  • Use ERRORS_CORRECTED to detect poor quality barcodes

ResultPointCallback Usage:

  • Implement for real-time visual feedback during scanning
  • Useful for mobile apps to show detection progress
  • Points may be reported multiple times during detection
  • Filter or deduplicate points if needed for visualization

Performance:

  • Result objects are lightweight and can be cached
  • ResultPoint objects are immutable and thread-safe
  • Avoid creating unnecessary Result copies
  • Reuse ResultPointCallback instances across multiple scans

See Also

  • Core Reading and Writing - Reader methods return Result objects
  • Result Parsing - Parse Result into structured data types
  • Configuration Hints - NEED_RESULT_POINT_CALLBACK hint
  • Exception Handling - Exceptions vs. Result metadata
  • Bit Structures - ResultPoint coordinates on BitMatrix

Install with Tessl CLI

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

docs

index.md

tile.json