zoukankan      html  css  js  c++  java
  • Swift 快速生成二维码

     1 // 生成二维码
     2 final class QRGenerator {
     3     static func generate(from string: String) -> UIImage? {
     4         let context = CIContext()
     5 //        let data = string.data(using: String.Encoding.ascii)
     6         let data = string.data(using: String.Encoding.utf8)
     7 
     8         if let filter = CIFilter(name: "CIQRCodeGenerator") {
     9             filter.setValue(data, forKey: "inputMessage")
    10             let transform = CGAffineTransform(scaleX: 7, y: 7)
    11             if let output = filter.outputImage?.transformed(by: transform), let cgImage = context.createCGImage(output, from: output.extent) {
    12                 return UIImage(cgImage: cgImage)
    13             }
    14         }
    15         return nil
    16     }
    17 }

      

    ASCII编码:最早只有127个字母被编码到计算机里,也就是大小写英文字母、数字和一些符号,这个编码表被称为ASCII编码。

    .ascii仅支持英文,.utf8支持中英文

     附:三种常见字符编码格式的介绍

  • 相关阅读:
    L2-004. 这是二叉搜索树吗?
    CF934A A Compatible Pair
    CF937B Vile Grasshoppers
    CF940B Our Tanya is Crying Out Loud
    ZOJ 3182 Nine Interlinks
    ZOJ 3175 Number of Containers
    Codeforces Round #193 (Div. 2) B
    CodeForces 149D Coloring Brackets
    POJ 2653 Pick-up sticks(计算几何)
    UVA 12506 Shortest Names
  • 原文地址:https://www.cnblogs.com/madarax/p/9702369.html
Copyright © 2011-2022 走看看