Skip to content

Instantly share code, notes, and snippets.

@yutelin
Created June 13, 2015 14:50
Show Gist options
  • Save yutelin/8d3daeb8a33d5786cb6f to your computer and use it in GitHub Desktop.
Save yutelin/8d3daeb8a33d5786cb6f to your computer and use it in GitHub Desktop.
//Reference: http://stackoverflow.com/questions/12051118/is-there-a-way-to-generate-qr-code-image-on-ios#comment48548881_22296488
import Foundation
import UIKit
extension String{
var qrcode: CIImage {
//let data = self.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false)
let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter.setValue(data, forKey: "inputMessage")
filter.setValue("Q", forKey: "inputCorrectionLevel")
let image = filter.outputImage
//fix blurry: http://stackoverflow.com/questions/12051118/is-there-a-way-to-generate-qr-code-image-on-ios#comment48548881_22296488
let transform = CGAffineTransformMakeScale(5.0, 5.0)
return image.imageByApplyingTransform(transform)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment