ios - 如何从设备中的图像读取二维码

标签 ios swift3 qr-code

我已经在我的 iOS 应用程序中多次使用从相机读取 QR 码。 但是这次我想从我的设备上已经存储的图像中获取我的 QR 码,例如相册中的图像。 最好的方法是什么?

最佳答案

您可以使用 CoreImage 来实现此目的。您可以使用 CIDetector 类检查 CIDetectorType 是否为 CIDetectorTypeQRCode 类型。您可以利用这个code

他们用来从图像中检测 QRCode 的函数是

 func performQRCodeDetection(_ image: CIImage) -> (outImage: CIImage?, decode: String) {
    var resultImage: CIImage?
    var decode = ""
    if let detector = detector {
      let features = detector.features(in: image)
      for feature in features as! [CIQRCodeFeature] {
        resultImage = drawHighlightOverlayForPoints(image, topLeft: feature.topLeft, topRight: feature.topRight,
          bottomLeft: feature.bottomLeft, bottomRight: feature.bottomRight)
        decode = feature.messageString!
      }
    }
    return (resultImage, decode)
}

关于ios - 如何从设备中的图像读取二维码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45298524/

相关文章:

ios - 如何使用 Twilio Swift SDK 取消注册 VOIP 推送通知

objective-c - 为 UITableView 的每个部分添加单独的标题

ios - 从 Firebase 读取/检索数据

ios - 如何在 init 中初始化 Objective C 类变量?

ios - UICollectionView 加载图像无法获取正确的单元格 swift 3

javascript - Cordova BarcodeScanner 连续读取

iPhone : How to get each element from QR code vCard?

java - 网络摄像头 - 检测 QR 码,拍摄快照和解码

ios - 如何检测应用程序何时从备份中恢复?

iphone - 是系统框架(如UIKIt.framework,CoreGraphics.framework)静态库还是动态库