liufan321 / SwiftQRCode

Simple QRCode detector and generator in Swift
MIT License
504 stars 133 forks source link

cant save to png file #30

Open jaydenhe opened 7 years ago

jaydenhe commented 7 years ago

UIImagePNGRepresentation always return nil

by the way: qrImageView.image = QRCode.generateImage(Token.base64EncodedString(), avatarImage:nil)

if let qrImage = qrImageView.image { let vc = UIActivityViewController(activityItems: [qrImage] as [Any], applicationActivities: [])
self.present(vc, animated: true, completion: nil) } I cant share the QRCode

Geeroz commented 7 years ago

my work around was to draw the qrImage in context then save from there.

let QRImage = QRCode.generateImage(qrString, avatarImage: nil, color: CIColor.init(red: 0.99, green: 0.27, blue: 0.12), backColor: CIColor.init(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.0))

UIGraphicsBeginImageContext(CGSize(width: 360, height: 360))
QRImage?.draw(in: CGRect(x: 0, y: 0, width: 360, height: 360))
let contextImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

data = UIImagePNGRepresentation(contextImage);