in my swift 2 app i can generate a QR Code like this:
let data = "1234567890".dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter!.setValue(data, forKey: "inputMessage")
filter!.setValue("Q", forKey: "inputCorrectionLevel")
qrcodeImage = filter!.outputImage
let transformedImage = qrcodeImage.imageByApplyingTransform(CGAffineTransformMakeScale(150, 150))
QRCodeImage.image = UIImage(CIImage: transformedImage)
but my QR Code get an white background image, but i would like to have an transparent background.
i tried something like this:
QRCodeImage.backgroundColor = UIColor.clearColor()
but this doesn't work. any idea ? :)
It seems like the CIQRCodeGenerator filter always uses black and white.
You can pass the output into a CIMaskToAlpha filter to convert it to transparent:

And first you might want to use CIColorInvert to swap white & black.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With