ios - 如何从一维条码图像解码

标签 ios swift

以下代码仅适用于从二维码图像解码,不适用于一维条码。

我不想使用任何第三方库。

是否可以获取条码图像的任何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/

相关文章:

iphone - UIRefreshControl 问题

ios - 试图保存 NSManagedObjectContext 不工作

swift - 获取 clang : error: linker command failed with exit code 1 (use -v to see invocation) while google signing

ios - 有人可以解释创建 TableView 的基本过程吗?

ios - 导航栏清除颜色为黑色

ios - 如何有效的在 iOS 项目中添加 iOS 框架

ios - 未调用 UIPickerView didSelectRow

Swift Forin-在哪里执行过滤或跳过(继续)?

ios - 如何修改现有函数以将数据返回到变量

ios - (Swift) 为键盘移动 View ?