Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When setting QRCode's backgroundColor clear. It comes out to be black background. #48

Open
LoKiLyn opened this issue May 24, 2017 · 3 comments

Comments

@LoKiLyn
Copy link

LoKiLyn commented May 24, 2017

No description provided.

@viniciusromani
Copy link

Same problem here. Any idea of a fix or a workaround?

@viniciusromani
Copy link

Hey @LoKiLyn I've got a workaround over here, I still didn't find a reasonable explanation to why this is happening though. This is what I came up with:

func applyTransaparentBackground() -> UIImage? {
        guard let rawImageReference = self.cgImage else { return self }
        let colorMasking: [CGFloat] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
        UIGraphicsBeginImageContext(self.size)
        guard let maskedImageReference = rawImageReference.copy(maskingColorComponents: colorMasking) else { return self }
        guard let context = UIGraphicsGetCurrentContext() else { return self }
        context.translateBy(x: 0.0, y: self.size.height)
        context.scaleBy(x: 1.0, y: -1.0)
        context.draw(maskedImageReference, in: CGRect(origin: CGPoint.zero, size: self.size))
        let finalImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return finalImage
    }

It basically masks all cg image colors to some other color based on 255 scale, this is mapped on that array called colorMasking (Credits go to: ankmara at https://stackoverflow.com/questions/35044784/changing-color-from-white-to-transparent-uiimage). This is not an ideal solution but it solves our problem.

PS. The function is inside an UIImage Extension in my project. It needs to be there otherwise, you should replace self to an UIImage object.

Best,

@LoKiLyn
Copy link
Author

LoKiLyn commented Sep 15, 2017

@viniciusromani
Thanks for ur share! Your solution solved my problem.
I guess the problem is that the lib used some function unsupported below iOS 9.
I used the following to partly resolve the problem.

    var qrCode = 🔳(self.wifiInformation)
     if #available(iOS 9, *) {
           qrCode.backgroundColor = CIColor(color: UIColor.clear)
        } else {
            // error backgroundColor with UIColor.clear at 8.2
            qrCode.backgroundColor = CIColor(color: color4)
     }

I'll look into it later. ^-^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants