
import UIKitclass VIEwController: UIVIEwController,UIImagePickerControllerDelegate,UINavigationControllerDelegate { overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() let button = UIbutton.init(type: UIbuttonType.custom) button.frame = CGRect.init(x: 20,y: 300,wIDth: 300,height: 40) button.setTitle("点击获取相册二维码图片信息",for: UIControlState.normal) button.setTitlecolor(UIcolor.black,for: UIControlState.normal) button.addTarget(self,action: #selector(self.getimage),for: UIControlEvents.touchUpInsIDe) self.vIEw.addSubvIEw(button) } func getimage() { let imagePickCST = UIImagePickerControllerSourceType.photolibrary let imagePickC = UIImagePickerController.init() imagePickC.sourceType = imagePickCST imagePickC.delegate = self self.present(imagePickC,animated: true,completion: nil) } func imagePickerController(_ picker: UIImagePickerController,dIDFinishPickingMediawithInfo info: [String : Any]) { picker.dismiss(animated: true,completion: nil) //获取到的原始图片 let image = info[UIImagePickerControllerOriginalimage] let imageData = UIImagePNGRepresentation(image as! UIImage) let ciImage = CIImage(data: imageData!) //初始化一个检测器 let detector = CIDetector(ofType: CIDetectorTypeQRCode,context: nil,options: [CIDetectorAccuracy:CIDetectorAccuracyLow]) //检测到的结果数组 let array = detector?.features(in: ciImage!) //取出数组中的第一个结果 if (array?.count)! > 0 { let result: CiqrCodeFeature = array!.first as! CiqrCodeFeature print(result.messageString!) } } overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. }} 总结 以上是内存溢出为你收集整理的二维码---相册识别 swift全部内容,希望文章能够帮你解决二维码---相册识别 swift所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)