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.

ParameterDescription
contentthe 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.

ParameterDescription
outputTypethe 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.

ParameterDescription
errorCorrectionLevelthe 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.

ParameterDescription
widththe 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.

ParameterDescription
heightthe 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.

ParameterDescription
borderMarginthe 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.

ParameterDescription
backgroundColorthe 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.

ParameterDescription
hexStringthe 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.

ParameterDescription
pixelColorthe 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.

ParameterDescription
hexStringthe 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.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.