@@ -14,30 +14,30 @@ fun main() {
14
14
15
15
val eclLowQRCode = QRCode .ofSquares()
16
16
.withErrorCorrectionLevel(ErrorCorrectionLevel .LOW ) // <- See Here
17
- .withInformationDensity(1 ) // <- Setting this will make the code NOT compute a value
17
+ .withInformationDensity(1 ) // <- Setting this to >= 1 will make the code NOT compute a value
18
18
.build(qrCodeData)
19
19
.also { println (" [Low] ECL: ${it.errorCorrectionLevel} , Information Density: ${it.informationDensity} " ) }
20
20
val eclLowPngData = eclLowQRCode.renderToBytes()
21
21
22
22
val eclMediumQRCode = QRCode .ofSquares()
23
23
.withErrorCorrectionLevel(ErrorCorrectionLevel .MEDIUM ) // <- See Here
24
- .withInformationDensity(1 ) // <- Setting this will make the code NOT compute a value
24
+ .withInformationDensity(1 ) // <- Setting this to >= 1 will make the code NOT compute a value
25
25
.build(qrCodeData)
26
26
.also { println (" [Medium] ECL: ${it.errorCorrectionLevel} , Information Density: ${it.informationDensity} " ) }
27
27
val eclMediumPngData = eclMediumQRCode.renderToBytes()
28
28
29
29
// ECL High: we need to add +1 to the information density because of the extra data added by the ECL
30
30
val eclHighQRCode = QRCode .ofSquares()
31
31
.withErrorCorrectionLevel(ErrorCorrectionLevel .HIGH ) // <- See Here
32
- .withInformationDensity(2 ) // <- Setting this will make the code NOT compute a value
32
+ .withInformationDensity(2 ) // <- Setting this to >= 1 will make the code NOT compute a value
33
33
.build(qrCodeData)
34
34
.also { println (" [High] ECL: ${it.errorCorrectionLevel} , Information Density: ${it.informationDensity} " ) }
35
35
val eclHighPngData = eclHighQRCode.renderToBytes()
36
36
37
37
// ECL Very High: we need to add +1 to the information density because of the extra data added by the ECL
38
38
val eclVeryHighQRCode = QRCode .ofSquares()
39
39
.withErrorCorrectionLevel(ErrorCorrectionLevel .VERY_HIGH ) // <- See Here
40
- .withInformationDensity(2 ) // <- Setting this will make the code NOT compute a value
40
+ .withInformationDensity(2 ) // <- Setting this to >= 1 will make the code NOT compute a value
41
41
.build(qrCodeData)
42
42
.also { println (" [Very High] ECL: ${it.errorCorrectionLevel} , Information Density: ${it.informationDensity} " ) }
43
43
val eclVeryHighPngData = eclVeryHighQRCode.renderToBytes()
@@ -56,6 +56,14 @@ fun main() {
56
56
.also { println (" [Default - ECL High] ECL: ${it.errorCorrectionLevel} , Information Density (computed): ${it.informationDensity} " ) }
57
57
val eclDefaultLowPngData = eclDefaultLowQRCode.renderToBytes()
58
58
59
+ // ECL Very High + Info Density: Using the maximum values to showcase how the QRCode grows given these parameters
60
+ val denseQRCode = QRCode .ofSquares()
61
+ .withErrorCorrectionLevel(ErrorCorrectionLevel .VERY_HIGH ) // <- See Here
62
+ .withInformationDensity(40 ) // <- Maximum value
63
+ .build(qrCodeData)
64
+ .also { println (" [Dense] ECL: ${it.errorCorrectionLevel} , Information Density: ${it.informationDensity} " ) }
65
+ val densePngData = denseQRCode.renderToBytes()
66
+
59
67
// -----------------------
60
68
// JVM-only code (saves the PNG Bytes to a file)
61
69
FileOutputStream (" examples/kotlin/example06-ecl-low.png" ).use { it.write(eclLowPngData) }
@@ -64,4 +72,5 @@ fun main() {
64
72
FileOutputStream (" examples/kotlin/example06-ecl-very-high.png" ).use { it.write(eclVeryHighPngData) }
65
73
FileOutputStream (" examples/kotlin/example06-ecl-default.png" ).use { it.write(eclDefaultPngData) }
66
74
FileOutputStream (" examples/kotlin/example06-ecl-default-high.png" ).use { it.write(eclDefaultLowPngData) }
75
+ FileOutputStream (" examples/kotlin/example06-dense.png" ).use { it.write(densePngData) }
67
76
}
0 commit comments