Created
March 1, 2019 13:49
-
-
Save ivan-ushakov/5da7803b8f0535fdd93a3de2168811fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import CoreImage | |
func createQRFromString(str: String) -> CIImage? { | |
let stringData = str.data(using: .utf8) as? NSData | |
guard let f1 = CIFilter(name: "CIQRCodeGenerator") else { | |
return nil | |
} | |
f1.setValue(stringData, forKey: "inputMessage") | |
f1.setValue("H", forKey: "inputCorrectionLevel") | |
return f1.outputImage?.transformed(by: CGAffineTransform(scaleX: 5.0, y: 5.0)) | |
} | |
if let img = createQRFromString(str: "") { | |
let ctx = CIContext(options:nil) | |
if let cgImage = ctx.createCGImage(img, from: img.extent) { | |
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 256, height: 256)) | |
imageView.contentMode = .center | |
imageView.image = UIImage(cgImage: cgImage) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment