-
Notifications
You must be signed in to change notification settings - Fork 198
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
Comments
Same problem here. Any idea of a fix or a workaround? |
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, |
@viniciusromani
I'll look into it later. ^-^ |
No description provided.
The text was updated successfully, but these errors were encountered: