Created
December 12, 2016 08:45
-
-
Save yarshure/65a64ffcfbda0ec5af32db9cb4904679 to your computer and use it in GitHub Desktop.
CIQRCodeGenerator CoreImage
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
| let base64Encoded = proxy.base64String() | |
| let stringData = base64Encoded.data(using: .utf8, allowLossyConversion: false) | |
| let filter = CIFilter(name: "CIQRCodeGenerator") | |
| guard let f = filter else { | |
| return | |
| } | |
| f.setValue(stringData, forKey: "inputMessage") | |
| f.setValue("M", forKey: "inputCorrectionLevel") | |
| guard let image = f.outputImage else { | |
| return | |
| } | |
| let cgImage = CIContext(options:nil).createCGImage(image, from:image.extent ) | |
| let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB(); | |
| let bytesPerRow = 2560 | |
| let info = CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue | |
| let newContext:CGContext = CGContext(data: nil, width: 500 , height: 500, bitsPerComponent: 8, bytesPerRow: bytesPerRow, space: colorSpace,bitmapInfo: info )!; | |
| newContext.interpolationQuality = .none | |
| newContext.draw(cgImage!, in: CGRect.init(x: 0, y: 0, width: 500, height: 500)) | |
| let newImage:CGImage = newContext.makeImage()!; | |
| let nsImage = NSImage.init(cgImage:newImage, size: CGSize.init(width: 250 , height: 250)) | |
| self.imageView.image = nsImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment