# QRose-CPF
**Repository Path**: xcode_xiao/qrose-cpf
## Basic Information
- **Project Name**: QRose-CPF
- **Description**: 【兼容鸿蒙版本,Android/iOS/OHOS】轻量级、灵活的条形码生成库,支持多种格式,例如 QR、UPC 和 EAN。提供高度自定义、可缩放矢量图形,并可导出为 PNG、JPEG 和 WEBP 格式。
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-11-10
- **Last Updated**: 2026-11-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# QRose





QR code and barcode generation library for Compose Multiplatform
Why QRose?
- **Lightweight** - doesn't contain any dependencies except of `compose.ui`.
- **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.
- **Multiplatform** - supports all the targets supported by Compose Multiplatform.
Compose-free encoders are available **for each** Kotlin target.
- **Multiformat** - multiple formats supported: `QR`, `Data Matrix`, `Aztec`, `PDF417`, `UPC`, `EAN`, `Code 128/93/39`, `Codabar`, `ITF`.
# Installation
[](https://central.sonatype.com/artifact/io.github.alexzhirkevich/qrose)
```toml
[versions]
qrose=""
[libraries]
# For QR codes
qrose-qr = { module = "io.github.alexzhirkevich:qrose", version.ref = "qrose" }
# For 2D matrix & stacked codes (Data Matrix, Aztec, PDF417)
qrose-matrix = { module = "io.github.alexzhirkevich:qrose-matrix", version.ref = "qrose" }
# For single-dimension barcodes (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
```toml
# 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](#basic)
- [Design](#design)
- [Customize (extend)](#customize)
- [Data Types](#data-types)
- [Export Image](#export)
- [Encoders (without Compose)](#encoders)
## 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.
```kotlin
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:
```kotlin
val qrcodePainter = rememberQrCodePainter(
data = "https://example.com",
ballShape = QrBallShape.circle(),
darkPixelShape = QrPixelShape.roundCorners(),
frameShape = QrFrameShape.roundCorners(.25f),
darkBrush = QrBrush.brush {
Brush.linearGradient(
0f to Color.Red,
1f to Color.Blue,
end = Offset(it, it)
)
},
frameBrush = QrBrush.solid(Color.Black),
logoPainter = rememberQrCodePainter("123"),
logoPadding = QrLogoPadding.Natural(.1f),
logoShape = QrLogoShape.circle(),
logoSize = 0.2f,
)
```
Or with DSL constructor:
```kotlin
val logoPainter : Painter = painterResource("logo.png")
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 {
Brush.linearGradient(
0f to Color.Red,
1f to Color.Blue,
end = Offset(it, it)
)
}
frame = QrBrush.solid(Color.Black)
}
}
```
## Customize
You can create your own shapes for each QR code part, for example:
```kotlin
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`](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/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:
```kotlin
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:
```kotlin
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:
```kotlin
/**
* 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
```
```kotlin
val encoder : MatrixCodeEncoder = QroseEncoders.QR()
val code : Matrix2D = encoder.encode("https://example.com")
```