标签:margin smi nali 二维码 self bsp idf nis nal
import UIKit
class firstViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
var picker :UIImagePickerController!
@IBAction func button(_ sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
self.present(picker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
//获取选择的图片
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
//二维码读取
DispatchQueue.global().async {
let imageData = UIImagePNGRepresentation(image)
let ciImage:CIImage=CIImage(data: imageData!)!
let detector = CIDetector(ofType: CIDetectorTypeQRCode, context:nil,options:[CIDetectorAccuracy:CIDetectorAccuracyHigh])
let feature = detector?.features(in: ciImage)
let f = feature?.first as! CIQRCodeFeature
print(f.messageString ?? "")
}
//返回
picker.dismiss(animated: true, completion: {
() -> Void in
})
}
}
标签:margin smi nali 二维码 self bsp idf nis nal
原文地址:http://www.cnblogs.com/chenxiaopao/p/7775141.html