SHARE
TWEET

Untitled

a guest Sep 12th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import UIKit
  2. import CoreImage
  3.  
  4. struct Bartendar {
  5.  
  6.     /// 生成二维码
  7.     ///
  8.     /// - Parameters:
  9.     ///   - content: 二维码内容
  10.     ///   - completion: 生成后回调
  11.     static func createAnQRCode(withContent content: String, completion: @escaping ((UIImage?) -> Void)) {
  12.         DispatchQueue.global().async {
  13.             let data = content.data(using: .utf8)
  14.  
  15.             var result: UIImage?
  16.             if let filter = CIFilter(name: "CIQRCodeGenerator") {
  17.                 filter.setValue(data, forKey: "inputMessage")
  18.  
  19.                 result = {
  20.                     let transform = CGAffineTransform(scaleX: 3, y: 3)
  21.                     if let output = filter.outputImage?.transformed(by: transform) {
  22.                         return UIImage(ciImage: output)
  23.                     }
  24.                     return nil
  25.                 }()
  26.             }
  27.  
  28.             completion(result)
  29.         }
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top