public final class QrCode extends Object
This class covers the QR Code model 2 specification, supporting all versions (sizes) from 1 to 40, all 4 error correction levels, and only 3 character encoding modes.
| Modifier and Type | Class and Description |
|---|---|
static class |
QrCode.Ecc
Represents the error correction level used in a QR Code symbol.
|
| Modifier and Type | Field and Description |
|---|---|
QrCode.Ecc |
errorCorrectionLevel
The error correction level used in this QR Code symbol.
|
int |
mask
The mask pattern used in this QR Code symbol, in the range 0 to 7 (i.e.
|
static int |
MAX_VERSION |
static int |
MIN_VERSION |
int |
size
The width and height of this QR Code symbol, measured in modules.
|
int |
version
This QR Code symbol's version number, which is always between 1 and 40 (inclusive).
|
| Constructor and Description |
|---|
QrCode(int ver,
QrCode.Ecc ecl,
byte[] dataCodewords,
int mask)
Creates a new QR Code symbol with the specified version number, error correction level, binary data array, and mask number.
|
| Modifier and Type | Method and Description |
|---|---|
static QrCode |
encodeBinary(byte[] data,
QrCode.Ecc ecl)
Returns a QR Code symbol representing the specified binary data string at the specified error correction level.
|
static QrCode |
encodeSegments(List<QrSegment> segs,
QrCode.Ecc ecl)
Returns a QR Code symbol representing the specified data segments at the specified error correction
level or higher.
|
static QrCode |
encodeSegments(List<QrSegment> segs,
QrCode.Ecc ecl,
int minVersion,
int maxVersion,
int mask,
boolean boostEcl)
Returns a QR Code symbol representing the specified data segments with the specified encoding parameters.
|
static QrCode |
encodeText(String text,
QrCode.Ecc ecl)
Returns a QR Code symbol representing the specified Unicode text string at the specified error correction level.
|
boolean |
getModule(int x,
int y)
Returns the color of the module (pixel) at the specified coordinates, which is either
false for white or true for black.
|
BufferedImage |
toImage(int scale,
int border)
Returns a new image object representing this QR Code, with the specified module scale and number
of border modules.
|
String |
toSvgString(int border)
Based on the specified number of border modules to add as padding, this returns a
string whose contents represents an SVG XML file that depicts this QR Code symbol.
|
public static final int MIN_VERSION
public static final int MAX_VERSION
public final int version
public final int size
public final QrCode.Ecc errorCorrectionLevel
null.public final int mask
public QrCode(int ver,
QrCode.Ecc ecl,
byte[] dataCodewords,
int mask)
This is a cumbersome low-level constructor that should not be invoked directly by the user.
To go one level up, see the encodeSegments(List,Ecc) function.
ver - the version number to use, which must be in the range 1 to 40, inclusiveecl - the error correction level to usedataCodewords - the raw binary user data to encodemask - the mask pattern to use, which is either -1 for automatic choice or from 0 to 7 for fixed choiceNullPointerException - if the byte array or error correction level is nullIllegalArgumentException - if the version or mask value is out of rangepublic static QrCode encodeText(String text, QrCode.Ecc ecl)
text - the text to be encoded, which can be any Unicode stringecl - the error correction level to use (will be boosted)NullPointerException - if the text or error correction level is nullIllegalArgumentException - if the text fails to fit in the largest version QR Code, which means it is too longpublic static QrCode encodeBinary(byte[] data, QrCode.Ecc ecl)
data - the binary data to encodeecl - the error correction level to use (will be boosted)NullPointerException - if the data or error correction level is nullIllegalArgumentException - if the data fails to fit in the largest version QR Code, which means it is too longpublic static QrCode encodeSegments(List<QrSegment> segs, QrCode.Ecc ecl)
This function allows the user to create a custom sequence of segments that switches between modes (such as alphanumeric and binary) to encode text more efficiently. This function is considered to be lower level than simply encoding text or binary data.
segs - the segments to encodeecl - the error correction level to use (will be boosted)NullPointerException - if the list of segments, a segment, or the error correction level is nullIllegalArgumentException - if the data is too long to fit in the largest version QR Code at the ECLpublic static QrCode encodeSegments(List<QrSegment> segs, QrCode.Ecc ecl, int minVersion, int maxVersion, int mask, boolean boostEcl)
This function allows the user to create a custom sequence of segments that switches between modes (such as alphanumeric and binary) to encode text more efficiently. This function is considered to be lower level than simply encoding text or binary data.
segs - the segments to encodeecl - the error correction level to use (may be boosted)minVersion - the minimum allowed version of the QR symbol (at least 1)maxVersion - the maximum allowed version of the QR symbol (at most 40)mask - the mask pattern to use, which is either -1 for automatic choice or from 0 to 7 for fixed choiceboostEcl - increases the error correction level if it can be done without increasing the version numberNullPointerException - if the list of segments, a segment, or the error correction level is nullIllegalArgumentException - if 1 ≤ minVersion ≤ maxVersion ≤ 40 is violated, or if mask
< −1 or mask > 7, or if the data is too long to fit in a QR Code at maxVersion at the ECLpublic boolean getModule(int x,
int y)
x - the x coordinate, where 0 is the left edge and size−1 is the right edgey - the y coordinate, where 0 is the top edge and size−1 is the bottom edgepublic BufferedImage toImage(int scale, int border)
scale - the module scale factor, which must be positiveborder - the number of border modules to add, which must be non-negativeIllegalArgumentException - if the scale or border is out of rangepublic String toSvgString(int border)
border - the number of border modules to add, which must be non-negativeCopyright © 2018. All rights reserved.