Skip to content

[Bug report] Data Matrix codes with inverted colors (light-on-dark / white-on-black) are not detected #1064

Description

@Iqra-Sattar

Describe the bug
The barcode scanner fails to detect Data Matrix codes when they use inverted polarity — i.e., light/white modules on a dark/black background. Standard dark-on-light Data Matrix codes scan correctly, but inverted codes are not recognized at all, even under good lighting and focus conditions.

To Reproduce

  1. Generate a standard Data Matrix code (dark modules on light background) — confirm it scans successfully.
  2. Generate the same data as a Data Matrix code with inverted colors (light modules on dark background).
  3. Start scanning with no format restriction.
  4. Observe that the inverted code is never detected, while the normal-polarity version scans without issue.

Expected behavior
The scanner should detect and decode Data Matrix codes regardless of color polarity (dark-on-light or light-on-dark), consistent with the ISO/IEC 16022 spec, which explicitly supports both polarities.

SDK Info:

  • SDK Name & Version: com.google.mlkit:barcode-scanning:17.3.0

Smartphone:

  • Device/Simulator: Android physical devices
  • Device/Simulator OS: Android 16 observed during testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions