Class QrCode

java.lang.Object
com.codename1.qrcode.QrCode

public final class QrCode extends Object

A QR code, generated from text or bytes: the module grid, and SVG for a page. The class is shared with the backend, which has no images: a client draws one with QrCodeImage, a server serves toSvg().

A device shows one so a phone can pair with it -- the address and a one-time token in a URL -- and a server puts one on an enrolment page:

QrCode code = QrCode.encode("https://10.0.0.5:8443/pair?t=4F9A2C", QrCode.ECC_MEDIUM);
Image image = QrCodeImage.create(code, 8);

Byte mode with UTF-8 text, versions 1 to 40, the four standard error correction levels and the mask with the lowest penalty (ISO/IEC 18004). The smallest version that holds the data is chosen.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Recovers about 30%, for a code printed where it gets scuffed.
    static final int
    Recovers about 7% of the code.
    static final int
    Recovers about 15%; the usual choice.
    static final int
    Recovers about 25%.
  • Method Summary

    Modifier and Type
    Method
    Description
    static QrCode
    encode(byte[] data, int ecc)
    Encodes bytes.
    static QrCode
    encode(String text, int ecc)
    Encodes text as UTF-8.
    int
    The error correction level, ECC_LOW to ECC_HIGH.
    int
    The mask pattern chosen, 0 to 7.
    int
    Modules per side, 17 + 4 * version, without the quiet zone.
    int
    The version, 1 to 40.
    boolean
    isDark(int x, int y)
    True for a dark module; false outside the grid, which is the quiet zone.
    The code as an SVG document, one unit per module with a four module quiet zone, for a web page or a printed label.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ECC_LOW

      public static final int ECC_LOW
      Recovers about 7% of the code.
      See Also:
    • ECC_MEDIUM

      public static final int ECC_MEDIUM
      Recovers about 15%; the usual choice.
      See Also:
    • ECC_QUARTILE

      public static final int ECC_QUARTILE
      Recovers about 25%.
      See Also:
    • ECC_HIGH

      public static final int ECC_HIGH
      Recovers about 30%, for a code printed where it gets scuffed.
      See Also:
  • Method Details

    • encode

      public static QrCode encode(String text, int ecc)
      Encodes text as UTF-8.
    • encode

      public static QrCode encode(byte[] data, int ecc)
      Encodes bytes. Throws IllegalArgumentException when they do not fit a version 40 code at this level (2953 bytes at ECC_LOW).
    • getSize

      public int getSize()
      Modules per side, 17 + 4 * version, without the quiet zone.
    • getVersion

      public int getVersion()
      The version, 1 to 40.
    • getErrorCorrection

      public int getErrorCorrection()
      The error correction level, ECC_LOW to ECC_HIGH.
    • getMask

      public int getMask()
      The mask pattern chosen, 0 to 7.
    • isDark

      public boolean isDark(int x, int y)
      True for a dark module; false outside the grid, which is the quiet zone.
    • toSvg

      public String toSvg()
      The code as an SVG document, one unit per module with a four module quiet zone, for a web page or a printed label.