简体   繁体   中英

How to read a QR from an image in the device

I have used already many times the reading of a QR code from the camera in my iOS apps. But this time I want to get my QR code from an image which is already stored on my device, say for example in the photo album. What is the best way to do that?

You can use CoreImage to achieve this. You can use the CIDetector class to check if CIDetectorType is of type CIDetectorTypeQRCode . You can make use of this code

Function that they use to detect QRCode from the image is

 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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM