- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IntegerBackground color, defaults to white, null means transparent.protected CharsetCharacter encoding.protected com.google.zxing.qrcode.decoder.ErrorCorrectionLevelError correction level.protected IntegerForeground color (QR code color).protected com.google.zxing.BarcodeFormatFormat of the generated code, defaults to QR code.protected intHeight.protected ImageLogo in the QR code.protected doubleCorner radius of the QR code logo, 0-1, as a ratio of width/height.protected IntegerMargin, 0-4.protected IntegerSets the amount of information in the QR code, can be set to an integer from 0-40.protected intScaling ratio for the logo in the QR code, e.g., 5 means 1/5 of the smaller dimension (width or height).protected com.google.zxing.datamatrix.encoder.SymbolShapeHintSymbol shape for DATA_MATRIX.protected intWidth. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the background color.Gets the character encoding.com.google.zxing.qrcode.decoder.ErrorCorrectionLevelGets the error correction level.Gets the foreground color.com.google.zxing.BarcodeFormatGets the code format.intGets the height.getImg()Gets the logo in the QR code.doubleGets the corner radius of the QR code logo, from 0 to 1, as a ratio of width/height.Gets the margin.Gets the amount of information in the QR code.intgetRatio()Gets the scaling ratio of the logo in the QR code, e.g., 5 means 1/5 of the smaller dimension (width or height).intgetWidth()Gets the width.static QrConfigof()Creates a QrConfig.static QrConfigof(int width, int height) Creates a QrConfig.setBackColor(Color backColor) Sets the background color, e.g., Color.BLUE.setCharset(Charset charset) Sets the character encoding.voidsetEnableEci(boolean enableEci) Enables or disables ECI encoding.setErrorCorrection(com.google.zxing.qrcode.decoder.ErrorCorrectionLevel errorCorrection) Sets the error correction level.setForeColor(Color foreColor) Sets the foreground color, e.g., Color.BLUE.getRGB().setFormat(com.google.zxing.BarcodeFormat format) Sets the code format, defaults to QR code.setHeight(int height) Sets the height.setImg(byte[] imageBytes) Sets the logo file for the QR code from a byte array.Sets the logo for the QR code.Sets the logo file for the QR code.Sets the logo file for the QR code.setImgRound(double imgRound) Sets the corner radius of the QR code logo, from 0 to 1, as a ratio of width/height.Sets the margin.setQrVersion(Integer qrVersion) Sets the amount of information in the QR code.setRatio(int ratio) Sets the scaling ratio of the logo in the QR code, e.g., 5 means 1/5 of the smaller dimension (width or height).setShapeHint(com.google.zxing.datamatrix.encoder.SymbolShapeHint shapeHint) Sets the symbol shape for DATA_MATRIX.setWidth(int width) Sets the width.toHints()Converts to Zxing's QR code configuration.
-
Field Details
-
width
protected int widthWidth. -
height
protected int heightHeight. -
foreColor
Foreground color (QR code color). -
backColor
Background color, defaults to white, null means transparent. -
margin
Margin, 0-4. -
qrVersion
Sets the amount of information in the QR code, can be set to an integer from 0-40. -
errorCorrection
protected com.google.zxing.qrcode.decoder.ErrorCorrectionLevel errorCorrectionError correction level. -
charset
Character encoding. -
img
Logo in the QR code. -
imgRound
protected double imgRoundCorner radius of the QR code logo, 0-1, as a ratio of width/height. -
ratio
protected int ratioScaling ratio for the logo in the QR code, e.g., 5 means 1/5 of the smaller dimension (width or height). -
shapeHint
protected com.google.zxing.datamatrix.encoder.SymbolShapeHint shapeHintSymbol shape for DATA_MATRIX. -
format
protected com.google.zxing.BarcodeFormat formatFormat of the generated code, defaults to QR code.
-
-
Constructor Details
-
QrConfig
public QrConfig()Constructor, default width and height are 300. -
QrConfig
public QrConfig(int width, int height) Constructor.- Parameters:
width- Width.height- Height.
-
-
Method Details
-
of
Creates a QrConfig.- Returns:
- A new QrConfig instance.
-
of
Creates a QrConfig.- Parameters:
width- Width.height- Height.- Returns:
- A new QrConfig instance.
-
getWidth
public int getWidth()Gets the width.- Returns:
- The width.
-
setWidth
Sets the width.- Parameters:
width- The width.- Returns:
- this
-
getHeight
public int getHeight()Gets the height.- Returns:
- The height.
-
setHeight
Sets the height.- Parameters:
height- The height.- Returns:
- this
-
getForeColor
Gets the foreground color.- Returns:
- The foreground color.
-
setForeColor
Sets the foreground color, e.g., Color.BLUE.getRGB().- Parameters:
foreColor- The foreground color.- Returns:
- this
-
getBackColor
Gets the background color.- Returns:
- The background color.
-
setBackColor
Sets the background color, e.g., Color.BLUE. Null means transparent background.- Parameters:
backColor- The background color.- Returns:
- this
-
getMargin
Gets the margin.- Returns:
- The margin.
-
setMargin
Sets the margin.- Parameters:
margin- The margin.- Returns:
- this
-
getQrVersion
Gets the amount of information in the QR code. Can be an integer from 0-40. The QR code image will also change based on the qrVersion. 0 means it changes automatically based on the input information.- Returns:
- The amount of information in the QR code.
-
setQrVersion
Sets the amount of information in the QR code. Can be an integer from 0-40. The QR code image will also change based on the qrVersion. 0 means it changes automatically based on the input information.- Parameters:
qrVersion- The amount of information in the QR code.- Returns:
- this
-
getErrorCorrection
public com.google.zxing.qrcode.decoder.ErrorCorrectionLevel getErrorCorrection()Gets the error correction level.- Returns:
- The error correction level.
-
setErrorCorrection
public QrConfig setErrorCorrection(com.google.zxing.qrcode.decoder.ErrorCorrectionLevel errorCorrection) Sets the error correction level.- Parameters:
errorCorrection- The error correction level.- Returns:
- this
-
setEnableEci
public void setEnableEci(boolean enableEci) Enables or disables ECI encoding. If enableEci=false, the QR code will not contain ECI information, meaning thecharsetcharacter encoding is set tonull. This is best for English characters. If enableEci=true, the QR code will contain ECI information, set according to thecharsetencoding. This is best for including Chinese characters, otherwise they will be garbled.- Reference 1: About the \000026 issue
- Reference 2: ECI (Extended_Channel_Interpretation) mode
- Reference 3: QR code generation details and principles
QR code encoding can be in ECI mode or non-ECI mode. In ECI mode, the first byte is used as an encoding identifier, whereas in non-ECI mode, it is the data stream directly. ECI mode is actually a better solution, as it allows for different encoding methods to be used during decoding based on the identifier. Non-ECI mode can only be processed in a single, unified way. However, some devices do not support ECI mode, which can lead to recognition failures. Using barcode scanners/guns might result in a "\000026" character. Using a mobile phone or other QR code parsing software will not have this issue.
The ECI encoding table shows that UTF-8 corresponds to "\000026" (or the number 22).
In summary: If the QR code content is entirely characters without Chinese, there is no need to encode using UTF-8. Encoding is only necessary for special symbols like Chinese.
- Parameters:
enableEci- Whether to enable ECI.- See Also:
-
getCharset
Gets the character encoding.- Returns:
- The character encoding.
-
setCharset
Sets the character encoding.- Parameters:
charset- The character encoding.- Returns:
- this
-
getImg
Gets the logo in the QR code.- Returns:
- The logo image.
-
setImg
Sets the logo file for the QR code.- Parameters:
imgPath- The path to the logo in the QR code.- Returns:
- this
-
setImg
Sets the logo file for the QR code from a byte array.- Parameters:
imageBytes- The byte array representation of the logo image.- Returns:
- this
-
setImg
Sets the logo file for the QR code.- Parameters:
imgFile- The logo file for the QR code.- Returns:
- this
-
setImg
Sets the logo for the QR code.- Parameters:
img- The logo for the QR code.- Returns:
- this
-
getImgRound
public double getImgRound()Gets the corner radius of the QR code logo, from 0 to 1, as a ratio of width/height.- Returns:
- The corner radius of the QR code logo.
-
setImgRound
Sets the corner radius of the QR code logo, from 0 to 1, as a ratio of width/height.- Parameters:
imgRound- The corner radius of the QR code logo.- Returns:
- this
-
getRatio
public int getRatio()Gets the scaling ratio of the logo in the QR code, e.g., 5 means 1/5 of the smaller dimension (width or height).- Returns:
- The scaling ratio of the logo in the QR code.
-
setRatio
Sets the scaling ratio of the logo in the QR code, e.g., 5 means 1/5 of the smaller dimension (width or height).- Parameters:
ratio- The scaling ratio of the logo in the QR code.- Returns:
- this
-
setShapeHint
Sets the symbol shape for DATA_MATRIX.- Parameters:
shapeHint- The symbol shape for DATA_MATRIX.- Returns:
- this
-
getFormat
public com.google.zxing.BarcodeFormat getFormat()Gets the code format.- Returns:
- The code format, defaults to QR code.
-
setFormat
Sets the code format, defaults to QR code.- Parameters:
format- The code format.- Returns:
- this
-
toHints
Converts to Zxing's QR code configuration.- Returns:
- The configuration.
-