diff --git a/Tinodios/Base.lproj/Main.storyboard b/Tinodios/Base.lproj/Main.storyboard index b9deecd7..7048d792 100644 --- a/Tinodios/Base.lproj/Main.storyboard +++ b/Tinodios/Base.lproj/Main.storyboard @@ -2316,8 +2316,9 @@ - + + @@ -2326,8 +2327,9 @@ - + + diff --git a/Tinodios/Utils.swift b/Tinodios/Utils.swift index 3521fb7f..536d5548 100644 --- a/Tinodios/Utils.swift +++ b/Tinodios/Utils.swift @@ -133,17 +133,19 @@ public class Utils { public static func generateQRCode(from string: String) -> UIImage? { let data = string.data(using: String.Encoding.ascii) + guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil } - if let filter = CIFilter(name: "CIQRCodeGenerator") { - filter.setValue(data, forKey: "inputMessage") - let transform = CGAffineTransform(scaleX: 3, y: 3) + filter.setValue(data, forKey: "inputMessage") - if let output = filter.outputImage?.transformed(by: transform) { - return UIImage(ciImage: output) - } - } + guard let qrcode = filter.outputImage else { return nil } - return nil + // QR code is very small. Scaling it up without smoothing. + let scaledImageSize = qrcode.extent.size.applying(CGAffineTransform(scaleX: 3, y: 3)) + UIGraphicsBeginImageContext(scaledImageSize) + let scaledContext = UIGraphicsGetCurrentContext()! + scaledContext.interpolationQuality = .none + UIImage(ciImage: qrcode).draw(in: CGRect(origin: .zero, size: scaledImageSize)) + return UIGraphicsGetImageFromCurrentImageContext()! } }