Swift UIView转Image/二维码生产

释放双眼,带上耳机,听听看~!
///View转Image
static func getViewScreenshot(view: UIView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.main.scale)
view.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
///生产二维码
static func createQRForString(_ qrString: String?) -> UIImage? {
if let sureQRString = qrString {
let stringData = sureQRString.data(using: String.Encoding.utf8, allowLossyConversion: false)
let qrFilter = CIFilter(name: "CIQRCodeGenerator")
qrFilter?.setValue(stringData, forKey: "inputMessage")
qrFilter?.setValue("H", forKey: "inputCorrectionLevel")
let qrCIImage = qrFilter?.outputImage
let colorFilter = CIFilter(name: "CIFalseColor")!
colorFilter.setDefaults()
colorFilter.setValue(qrCIImage, forKey: "inputImage")
colorFilter.setValue(CIColor(red: 0, green: 0, blue: 0), forKey: "inputColor0")
colorFilter.setValue(CIColor(red: 1, green: 1, blue: 1), forKey: "inputColor1")
let codeImage = UIImage(ciImage: (colorFilter.outputImage!.transformed(by: CGAffineTransform(scaleX: 5, y: 5))))
return codeImage
}
return nil
}

人已赞赏
iOS文章

iOS11以上系统使用scrollRectToVisible回到顶部失效的解决方法

2020-2-15 6:10:47

iOS文章

iOS10中UISearchController对searchBar的修改

2020-2-15 7:55:02

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索