Hi guys, do you know any library which can generat...
# multiplatform
t
Hi guys, do you know any library which can generate QR codes and support KMM?
r
If you don’t find a suitable library right now for this, I think the easiest would be to use Ktor with an online API such as : https://www.qr-code-generator.com/qr-code-api
t
Thanks for your suggestion. My case can not depend on third-party API
h
m
Yeah, Korim seems to be it. Here's a link to community resourced library list. Very helpful, if anyone was not aware of it. https://github.com/AAkira/Kotlin-Multiplatform-Libraries#image
k
m
Unfortunately there is no support for native yet. Looks pretty cool though
t
thanks for all suggestions. I’m trying them one by one and I will provide feedback later.
After investigating them all, I decided to not use multi-platform lib and implement it on the native side instead. I choose https://github.com/g0dkar/qrcode-kotlin for android and JVM and this is work well. For the iOS I’m looking for the one.
s
For iOS you can use the CoreImage platform API
CIFilter.filterWithName("CIQRCodeGenerator")
to generate QR code.
t
Thank you 😎
b
Looks like adding whatever targets you're missing to https://github.com/g0dkar/qrcode-kotlin would be a relatively easy contribution since it's pure kotlin. Might be worth contributing to it instead of foregoing kmp approach for qrs
j
@Tung97 Hl Can you share your solution for generating QR code on iOS?
t
Copy code
actual fun genQrCode(value: String): ByteArray {
    val filter = CIFilter.QRCodeGenerator().apply {
        setValue(value, forKey = "inputMessage")
    }
    val outputImg = filter.outputImage ?: return byteArrayOf()
    val nsData = CIContext().JPEGRepresentationOfImage(
        outputImg,
        CGColorSpaceCreateDeviceRGB(),
        mapOf<Any?, String>()
    ) ?: return byteArrayOf()
    return ByteArray(nsData.length.toInt()).apply {
        usePinned {
            memcpy(it.addressOf(0), nsData.bytes, nsData.length)
        }
    }
}
I suggest you search solution for ojective-C, then convert it to kotlin by kotlin/native
1165 Views