A Kotlin Multiplatform (KMP) library for generating QR Codes. This library supports all QR Code Model 2 specifications, including versions 1 to 40, all error correction levels, and various encoding modes. It is designed to be lightweight and efficient, providing a flexible API for encoding text, binary data, and more into QR Codes.
- Support for all QR Code versions (1–40): Generate QR Codes of various sizes.
- Error correction levels: Includes support for LOW, MEDIUM, QUARTILE, and HIGH error correction levels.
- Encoding modes: Numeric, alphanumeric, byte, and Extended Channel Interpretation (ECI).
- Immutable and thread-safe: Designed for concurrent use in a multithreaded environment.
- Kotlin Multiplatform support: Can be used on JVM, Android, iOS, and other Kotlin-supported platforms.
Add the dependency to your build.gradle.kts
file:
dependencies {
implementation("io.github.goquati:qr:$VERSION")
}
For multiplatform projects, include the library in the common dependencies block.
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.github.goquati:qr:$VERSION")
}
}
}
}
Replace $VERSION
with the latest version available on Maven Central or your preferred package repository.
import io.github.goquati.qr.QrCode
import io.github.goquati.qr.QrCode.Ecc
val qrCode = QrCode.encodeText("Hello, World!", Ecc.HIGH)
println("QR Code size: ${qrCode.size}")
Access the color of specific modules (pixels) in the QR Code:
for (y in 0 until qrCode.size) {
for (x in 0 until qrCode.size) {
print(if (qrCode[x, y]) "██" else " ")
}
println()
}
val binaryData = byteArrayOf(0x01, 0x02, 0x03)
val qrCode = QrCode.encodeBinary(binaryData, Ecc.MEDIUM)
Use segments to optimize encoding and switch between modes:
import io.github.goquati.qr.QrSegment
val qrCode = QrCode.encodeSegments(Ecc.QUARTILE) {
addAlphanumeric("HELLO ")
addNumeric("12345")
}
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to open an issue or submit a pull request. Please ensure that your code adheres to the existing coding standards and includes appropriate tests.