alexzhirkevich/custom-qr-generator

QrVectorLogo is not correctly scaled with non whole size

Closed this issue · 2 comments

Library version: 1.6.0
Android version: 13

I'm using this simple vector image, that displays a circle

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="40dp"
    android:height="40dp"
    android:viewportWidth="40"
    android:viewportHeight="40">
    <path
        android:pathData="m0,20a20,20 0 0,1 40,0a20,20 0 0,1 -40,0z"
        android:fillColor="#000000" />
</vector>

When the size of the qr code view is not an integer - for example, I want it to take up part of the screen width, say 0.6, the logo is drawn rather pixelated. If I round up the size, it's drawn as it should be. Here is a sample code in Compose:

val textContent = LoremIpsum().values.first().take(300)
val context = LocalContext.current
val drawable = remember(textContent) {
    QrCodeDrawable(
        data = QrData.Text(textContent),
        options = QrVectorOptions.Builder()
            .setErrorCorrectionLevel(QrErrorCorrectionLevel.High)
            .setLogo(
                QrVectorLogo(
                    drawable = AppCompatResources.getDrawable(context, R.drawable.ic_logo),
                    padding = QrVectorLogoPadding.Natural(.28f),
                )
            )
            .setShapes(
                QrVectorShapes(
                    darkPixel = QrVectorPixelShape.RoundCorners(0.5f),
                    ball = QrVectorBallShape.Circle(1f),
                    frame = QrVectorFrameShape.Circle()
                )
            )
            .build(),
    )
}
Image(
    rememberDrawablePainter(drawable),
    contentDescription = null,
    contentScale = ContentScale.None,
    modifier = Modifier
        .size(300.5.dp)
)

Result with size 300.5.dp:

Result with size 300.dp:

Hi, @PhilipDukhov.

Thanks for reporting, reproduced in 1.6.0.

Can you please check if it reproduces in last snapshot com.github.alexzhirkevich:custom-qr-generator:2019e393a3. It seems to be fixed by itself :)

@alexzhirkevich cool, looks like it's indeed fixed 😁