Kotlin MIT

qrose

A pure-Kotlin barcode generation library with a stylized graphical implementation for Compose Multiplatform

A

alexzhirkevich

Dernière activité 16 sept. 2026
alexzhirkevich/qrose

535

étoiles

29

forks

2

issues ouvertes

aztecbarcodecodabarcode-generatorcomposecompose-multiplatformdatamatrixeanitfjetpack-composekotlinkotlin-multiplatformmultiplatformpdf417qrqr-codeqrcodeupc

Ce README est souvent en anglais.

QRose

badge-Android badge-iOS badge-JVM badge-macOS badge-web

A pure-Kotlin barcode generation library with a customizable graphical implementation for Compose Multiplatform

Screenshot 2023-10-10 at 10 34 05

Why QRose?

  • Lightweight - doesn't bring any dependencies except of compose.ui.
  • Multiformat - multiple formats supported: QR, Data Matrix, Aztec, PDF417, UPC, EAN, Code 128/93/39, Codabar, ITF.
  • Multiplatform - Encoders are available for each Kotlin target. Graphical components are available for all targets supported by the Compose Multiplatform.
  • Flexible - high customization ability that is open for extension.
  • Efficient - declare and render codes synchronously right from the composition in 60+ fps.
  • Scalable - no raster bitmaps, only scalable vector graphics.

Installation

Maven Central

[versions]
qrose="<version>"

[libraries]
# For QR code painter
qrose-qr = { module = "io.github.alexzhirkevich:qrose", version.ref = "qrose" }
# For 2D matrix & stacked code painters (Data Matrix, Aztec, PDF417)
qrose-matrix = { module = "io.github.alexzhirkevich:qrose-matrix", version.ref = "qrose" }
# For single-dimension barcode painters (UPC, EAN, Code128, ...)
qrose-oned = { module = "io.github.alexzhirkevich:qrose-oned", version.ref = "qrose" }

Encoder modules do additionally support all K/native targets and Node

# For matrix encoders without Compose (optional, included in qrose-matrix)
qrose-encoder-matrix = { module = "io.github.alexzhirkevich:qrose-encoder-matrix", version.ref = "qrose" }
# For barcode encoders without Compose (optional, included in qrose-oned)
qrose-encoder-oned = { module = "io.github.alexzhirkevich:qrose-encoder-oned", version.ref = "qrose" }

Usage

Basic

You can create code right in composition using rememberQrCodePainter, rememberDataMatrixPainter, rememberAztecPainter, rememberPdf417Painter, rememberBarcodePainter. Or use QrCodePainter, DataMatrixPainter, AztecPainter, Pdf417Painter, BarcodePainter to create it outside of Compose.

Image(
    painter = rememberQrCodePainter("https://example.com"),
    contentDescription = "QR code referring to the example.com website"
)

Image(
    painter = rememberDataMatrixPainter("https://example.com"),
    contentDescription = "Data Matrix code"
)

Image(
    painter = rememberAztecPainter("https://example.com"),
    contentDescription = "Aztec code"
)

Image(
    painter = rememberPdf417Painter("https://example.com"),
    contentDescription = "PDF417 barcode"
)

Image(
    painter = rememberBarcodePainter("9780201379624", BarcodeType.EAN13),
    contentDescription = "EAN barcode for some product"
)

Design

QR codes have flexible styling options, for example:

val qrcodePainter = rememberQrCodePainter(
    data = "https://example.com",
    ballShape = QrBallShape.circle(),
    darkPixelShape = QrPixelShape.roundCorners(),
    frameShape = QrFrameShape.roundCorners(.25f),
    darkBrush = QrBrush.brush { size ->
        Brush.linearGradient(
            0f to Color.Red,
            1f to Color.Blue,
            end = Offset(size, size)
        )
    },
    frameBrush = QrBrush.solid(Color.Black),
    logoPainter = painterResource(Res.drawable.logo),
    logoPadding = QrLogoPadding.Natural(.1f),
    logoShape = QrLogoShape.circle(),
    logoSize = 0.2f,
)

Or with DSL constructor:

val logoPainter : Painter = painterResource(Res.drawable.logo)

val qrcodePainter : Painter = rememberQrCodePainter("https://example.com") {
    logo {
        painter = logoPainter
        padding = QrLogoPadding.Natural(.1f)
        shape = QrLogoShape.circle()
        size = 0.2f
    }

    shapes {
        ball = QrBallShape.circle()
        darkPixel = QrPixelShape.roundCorners()
        frame = QrFrameShape.roundCorners(.25f)
    }
    colors {
        dark = QrBrush.brush { size ->
            Brush.linearGradient(
                0f to Color.Red,
                1f to Color.Blue,
                end = Offset(size, size)
            )
        }
        frame = QrBrush.solid(Color.Black)
    }
}

Customize

You can create your own shapes for each QR code part, for example:

class MyCircleBallShape : QrBallShape {
    
    override fun Path.path(size: Float, neighbors: Neighbors): Path = apply {
        addOval(Rect(0f,0f, size, size))
    }
}

Note A path here uses PathFillType.EvenOdd that cannot be changed.

Data types

QR codes can hold various payload types: Text, Wi-Fi, E-mail, vCard, etc.

QrData object can be used to perform such encodings, for example:

val wifiData : String = QrData.wifi(ssid = "My Network", psk = "12345678")

val wifiCode = rememberQrCodePainter(wifiData)

Export

QR codes can be exported to PNG, JPEG and WEBP formats using toByteArray function:

val painter : Painter = QrCodePainter(
    data = "https://example.com",
    options =  QrOptions { 
        colors {
            //...
        }
    }
)

val bytes : ByteArray = painter.toByteArray(1024, 1024, ImageFormat.PNG)

Encoders

Using qrose-encoder-matrix and qrose-encoder-oned modules you can get barcode bit matrices/arrays without Compose graphical implementation.

The QroseEncoders object is used as an encoder factory for all types of codes. You can create encoders using the extension functions, for example:

/**
 * Creates a [MatrixCodeEncoder] that generates QR codes.
 */
fun QroseEncoders.QR(
    errorCorrection: QrErrorCorrection = QrErrorCorrection.L,
    maskPattern: QrMaskPattern = QrMaskPattern.PATTERN000
) : MatrixCodeEncoder

/**
 * Creates a [BarcodeEncoder] that generates Code 128 barcodes.
 */
fun QroseEncoders.Code128(
    compact : Boolean = true,
    forceCodeSet : Code128Type? = null
) : BarcodeEncoder
val encoder : MatrixCodeEncoder = QroseEncoders.QR()
val code : Matrix2D = encoder.encode("https://example.com")

Projets similaires

High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.

Javacc-plus-plusjava
Nnayuki
6,8 k étoiles1,3 k

ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Javaandroidbarcodebarcode-scanner
Zzxing
34,1 k étoiles9,4 k

a barcode creation lib for golang

Goaztec-codebarcodecodabar
Bboombuler
1,6 k étoiles184