Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class QrCode
- Object
- QrCode
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.
Fields
public static final int ECC_LOW = 0 | Recovers about 7% of the code. |
public static final int ECC_MEDIUM = 1 | Recovers about 15%; the usual choice. |
public static final int ECC_QUARTILE = 2 | Recovers about 25%. |
public static final int ECC_HIGH = 3 | Recovers about 30%, for a code printed where it gets scuffed. |
Methods
public static QrCode encode(String text, int ecc) | Encodes text as UTF-8. |
public static QrCode encode(byte[] data, int ecc) | Encodes bytes. |
public int getSize() | Modules per side, 17 + 4 * version, without the quiet zone. |
public int getVersion() | The version, 1 to 40. |
public int getErrorCorrection() | The error correction level, ECC_LOW to ECC_HIGH. |
public int getMask() | The mask pattern chosen, 0 to 7. |
public boolean isDark(int x, int y) | True for a dark module; false outside the grid, which is the quiet zone. |
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. |
Inherited methods
Field details
ECC_LOW
public static final int ECC_LOW = 0Recovers about 7% of the code.
ECC_MEDIUM
public static final int ECC_MEDIUM = 1Recovers about 15%; the usual choice.
ECC_QUARTILE
public static final int ECC_QUARTILE = 2Recovers about 25%.
ECC_HIGH
public static final int ECC_HIGH = 3Recovers about 30%, for a code printed where it gets scuffed.
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()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.