QRCodeOptions Class
Contains options specific to QR Code symbology.
Declaration
public class QRCodeOptions extends BarcodeOptions
Remarks
Refer to the following help topic for additional information: QR Code.
The following code snippet creates a QR Code barcode and customizes its encoding parameters:
import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import com.devexpress.system.drawing.*;
import com.devexpress.docs.Padding;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
byte[] logoBytes = Files.readAllBytes(Path.of("images/devexpress-logo.png"));
try (DXImage logo = DXImage.fromStream(new ByteArrayInputStream(logoBytes))) {
// Customize QR Code parameters.
QRCodeOptions options = new QRCodeOptions();
options.setErrorCorrectionLevel(QRCodeErrorCorrectionLevel.H);
options.setCompactionMode(QRCodeCompactionMode.AUTO);
options.setVersion(QRCodeVersion.VERSION_10);
options.setIncludeQuietZone(true);
options.setLogo(logo);
options.setPadding(new Padding(10));
options.setModuleSize(10);
options.setShowText(false);
// Customize QR Code frame parameters.
RectangleQRFrameOptions frameOptions = new RectangleQRFrameOptions();
frameOptions.setPadding(new Padding(10));
frameOptions.setFrameColor(Color.getOrange());
frameOptions.setFrameWidth(10);
frameOptions.setText("DevExpress");
frameOptions.setCornerRadius(10);
frameOptions.setTextAlignment(QRFrameTextAlignment.CENTER);
frameOptions.setTextColor(Color.getBlack());
frameOptions.setTextPosition(QRFrameTextPosition.BOTTOM);
options.setFrameOptions(frameOptions);
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
try (FileOutputStream fileStream = new FileOutputStream(
outputDir.resolve("qrcode.png").toFile());
BarcodeGenerator barcodeGenerator = new BarcodeGenerator(options)) {
barcodeGenerator.export(
"https://www.devexpress.com",
fileStream,
DXImageFormat.getPng());
}
}
}
}
Inherited Members
Inheritance
QRCodeOptions()
Initializes a new instance of the QRCodeOptions class.
Declaration
public QRCodeOptions()
Methods
getCompactionMode() Method
Gets the compaction mode for the QR code.
Declaration
public QRCodeCompactionMode getCompactionMode()
Returns
| Type | Description |
|---|---|
| QRCodeCompactionMode | An enumeration value that indicates the compaction mode. |
getErrorCorrectionLevel() Method
Gets the error correction level for the QR code.
Declaration
public QRCodeErrorCorrectionLevel getErrorCorrectionLevel()
Returns
| Type | Description |
|---|---|
| QRCodeErrorCorrectionLevel | An enumeration value that indicates the error correction level for the QR code. |
Remarks
QR Codes use the Reed-Solomon error correction algorithm and support four error correction levels. Higher error correction levels improve damage resistance but reduce storage capacity.
getFrameOptions() Method
Returns frame options for the QR code.
Declaration
public QRFrameOptions getFrameOptions()
Returns
| Type | Description |
|---|---|
| QRFrameOptions | An object that contains frame options for the QR code. |
getIncludeQuietZone() Method
Returns whether to include a quiet zone (a margin of empty space) around the code.
Declaration
public boolean getIncludeQuietZone()
Returns
| Type | Description |
|---|---|
| boolean |
|
getLogo() Method
Gets the logo image of the QR code.
Declaration
public DXImage getLogo()
Returns
| Type | Description |
|---|---|
| DXImage | The logo image. |
getVersion() Method
Gets the QR code version.
Declaration
public QRCodeVersion getVersion()
Returns
| Type | Description |
|---|---|
| QRCodeVersion | An enumeration value that specifies the QR code version. |
setCompactionMode(QRCodeCompactionMode value) Method
Sets the compaction mode for the QR code.
Declaration
public void setCompactionMode(QRCodeCompactionMode value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | QRCodeCompactionMode | An enumeration value that indicates the compaction mode. |
setErrorCorrectionLevel(QRCodeErrorCorrectionLevel value) Method
Sets the error correction level for the QR code.
Declaration
public void setErrorCorrectionLevel(QRCodeErrorCorrectionLevel value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | QRCodeErrorCorrectionLevel | An enumeration value that indicates the error correction level for the QR code. |
Remarks
QR Codes use the Reed-Solomon error correction algorithm and support four error correction levels. Higher error correction levels improve damage resistance but reduce storage capacity.
setFrameOptions(QRFrameOptions value) Method
Specifies frame options for the QR code.
Declaration
public void setFrameOptions(QRFrameOptions value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | QRFrameOptions | An object that contains frame options for the QR code. |
setIncludeQuietZone(boolean value) Method
Specifies whether to include a quiet zone (a margin of empty space) around the code.
Declaration
public void setIncludeQuietZone(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setLogo(DXImage value) Method
Sets the logo image for the QR code.
Declaration
public void setLogo(DXImage value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | DXImage | The logo image. |
setVersion(QRCodeVersion value) Method
Sets the QR code version.
Declaration
public void setVersion(QRCodeVersion value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | QRCodeVersion | An enumeration value that specifies the QR code version. |