This is a quick test to make QR Code Generator that will run on Swift Playground app on iPad. I sourced some of the code online from few forums.
The resulting QR Image on "Playground Preview" is stretched, however it seems to still work when I am using iPhone camera to scan it. Ideally the Playground Preview should not be stretched like this and keeping the QR image square. Saving the QR Code itself is another mystery.
The whole code is actually very simple, taking advantage of Core Image CIFilter "CIQRCodeGenerator" as below:
The resulting QR Image on "Playground Preview" is stretched, however it seems to still work when I am using iPhone camera to scan it. Ideally the Playground Preview should not be stretched like this and keeping the QR image square. Saving the QR Code itself is another mystery.
The whole code is actually very simple, taking advantage of Core Image CIFilter "CIQRCodeGenerator" as below:
import Foundation
import UIKit
import PlaygroundSupport
let data = "https://youtube.com/c/jimmygunawan".data(using: .utf8)
let filter = CIFilter(name: "CIQRCodeGenerator", withInputParameters: ["inputMessage" : data, "inputCorrectionLevel":"L"])
let ciimage = filter!.outputImage!
let transform = CGAffineTransform(scaleX: 20.0, y: 20.0)
let image = ciimage.transformed(by: transform)
let img = UIImage(ciImage: image)
PlaygroundPage.current.liveView = UIImageView(image: img)
SOURCE:
https://medium.com/@MedvedevTheDev/generating-basic-qr-codes-in-swift-63d7222aa011
http://www.jensmeder.de/git/2017/05/18/generating-qr-codes-with-core-image.html
Comments
Post a Comment