我已经在我的 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/