Fluent builder for rendering a QR code image, obtained via BarcodeManager.qrCode(). Chain the setter methods to configure the encoded content, image size, colours and error correction level, then call build() or buildAsString() to render the image. Unset options fall back to sensible defaults at render time.
Group: Builders
Methods
content(String content) · outputType(String outputType) · errorCorrectionLevel(String errorCorrectionLevel) · width(Integer width) · height(Integer height) · borderMargin(Integer borderMargin) · backgroundColor(Integer backgroundColor) · backgroundColorHex(String hexString) · pixelColor(Integer pixelColor) · pixelColorHex(String hexString) · build() · buildAsString()
content(String content)
Returns: QrCodeBuilder
Sets the raw content to encode into the QR code, for example a URL, a WiFi network configuration string, or an otpauth URI for authenticator enrolment. See the zxing project's Barcode Contents wiki page for the range of supported formats.
| Parameter | Description |
|---|---|
content | the raw string to encode |
outputType(String outputType)
Returns: QrCodeBuilder
Sets the image format to render, for example PNG or JPEG. Defaults to PNG if not set or blank.
| Parameter | Description |
|---|---|
outputType | the image format name, passed through to the underlying image writer |
errorCorrectionLevel(String errorCorrectionLevel)
Returns: QrCodeBuilder
Sets the QR code's error correction level, which controls how much of the code can be obscured or damaged and still scan correctly. L gives about 7% correction, M about 15%, Q about 25% and H about 30%. Must match one of the zxing ErrorCorrectionLevel names; an unrecognised value is ignored and the writer's own default applies.
| Parameter | Description |
|---|---|
errorCorrectionLevel | the error correction level name: L, M, Q or H |
width(Integer width)
Returns: QrCodeBuilder
Sets the rendered image width in pixels. If only one of width or height is set, the other is made to match it; if neither is set, both default to 200.
| Parameter | Description |
|---|---|
width | the image width in pixels |
height(Integer height)
Returns: QrCodeBuilder
Sets the rendered image height in pixels. If only one of width or height is set, the other is made to match it; if neither is set, both default to 200.
| Parameter | Description |
|---|---|
height | the image height in pixels |
borderMargin(Integer borderMargin)
Returns: QrCodeBuilder
Sets the width, in modules, of the quiet border around the QR code. Pass -1 to disable the border entirely.
| Parameter | Description |
|---|---|
borderMargin | the border margin, or -1 to disable it |
backgroundColor(Integer backgroundColor)
Returns: QrCodeBuilder
Sets the background colour as a packed ARGB integer, for example 4278198835 for hex FF002233. Defaults to white if not set.
| Parameter | Description |
|---|---|
backgroundColor | the background colour as a packed ARGB integer |
backgroundColorHex(String hexString)
Returns: QrCodeBuilder
Sets the background colour by parsing an ARGB or RGB HTML hex string, for example FF002233 or 002233.
| Parameter | Description |
|---|---|
hexString | the background colour as an ARGB or RGB hex string |
pixelColor(Integer pixelColor)
Returns: QrCodeBuilder
Sets the QR code's foreground pixel colour as a packed ARGB integer, for example 4278198835 for hex FF002233. Defaults to black if not set.
| Parameter | Description |
|---|---|
pixelColor | the pixel colour as a packed ARGB integer |
pixelColorHex(String hexString)
Returns: QrCodeBuilder
Sets the QR code's foreground pixel colour by parsing an ARGB or RGB HTML hex string, for example FF002233 or 002233.
| Parameter | Description |
|---|---|
hexString | the pixel colour as an ARGB or RGB hex string |
build()
Returns: byte[]
Renders the configured QR code and returns the encoded image bytes, in the format set by outputType. Any width, height or colour that was not explicitly set is defaulted before rendering.
buildAsString()
Returns: String
Renders the configured QR code, same as build(), and returns the image as a Base64-encoded string suitable for embedding directly in a data URI.