来这里,了解很多问题,发掘更多。
👇👇👇 传送门->LLPhotoBrowser👇👇👇
⚠️⚠️⚠️:以下内容来自于传送门链接👆👆👆
func tapAction() {
/// CIFilter
let filter = CIFilter.init(name: "CIQRCodeGenerator")
filter?.setDefaults()
/// Add Data
let data = "https://www.baidu.com".data(using: .utf8)
filter?.setValue(data, forKeyPath: "inputMessage")
/// Out Put
let outputImage = filter?.outputImage
/// Show QRCode
self.imageView.image = createUIImageFromCIImage(image: outputImage!, size: 200)
}
// 高清处理
func createUIImageFromCIImage(image: CIImage, size: CGFloat) -> UIImage {
let extent = image.extent.integral
let scale = min(size / extent.width, size / extent.height)
/// Create bitmap
let width: size_t = size_t(extent.width * scale)
let height: size_t = size_t(extent.height * scale)
let cs: CGColorSpace = CGColorSpaceCreateDeviceGray()
let bitmap: CGContext = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 0, space: cs, bitmapInfo: 1)!
let context = CIContext.init()
let bitmapImage = context.createCGImage(image, from: extent)
bitmap.interpolationQuality = .none
bitmap.scaleBy(x: scale, y: scale)
bitmap.draw(bitmapImage!, in: extent)
let scaledImage = bitmap.makeImage()
return UIImage.init(cgImage: scaledImage!)
}
注意
以上内容为个人整理,如果有问题有出入或者你有更好的解决方法,还请赐教哦,感谢。
我的邮箱 coderjianfeng@foxmail.com 👉👉👉 github传送门