以下代码仅适用于从二维码图像解码,不适用于一维条码。
我不想使用任何第三方库。
是否可以获取条码图像的任何CIQRCodeFeature
?
感谢您的帮助。
func scanCodeFromImage(image: UIImage) -> String? {
guard let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy : CIDetectorAccuracyHigh]), let ciImage = CIImage(image: image), let features = detector.features(in: ciImage) as? [CIQRCodeFeature] else { return nil }
var qrCodeText = ""
for feature in features {
if let message = feature.messageString {
qrCodeText += message
}
}
return qrCodeText
}
最佳答案
这不需要第三方库,Apple 提供了 AVFoundation framework
关注this为了更好地理解如何让它工作,您只需更改要扫描的条码类型,您可以选择多种不同类型或只选择一种类型。这也可以在不使用第三方库的情况下使用图像或直接来自相机来完成。
关于ios - 如何从一维条码图像解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57265471/