iOS从一维图像中获取消息字符串

时间:2017-02-22 06:32:06

标签: ios barcode

我可以使用二维条码图像获取字符串消息,并使用输入字符串生成二维条码图像,但如何使用一维条码获取字符串消息以及如何使用字符串生成一个?以下代码是关于二维条码:

+ (NSString *)decodeImage:(CIImage *)ciImage {
    NSDictionary *options = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
    CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:options];
    NSArray *features = [detector featuresInImage:ciImage];
    for (CIFeature *feature in features) {
        if ([feature isKindOfClass:[CIQRCodeFeature class]]) {
            CIQRCodeFeature *qrFeature = (CIQRCodeFeature *)feature;
            return qrFeature.messageString;
        }
    }
    return nil;
}

....

一维条码怎么样?

1 个答案:

答案 0 :(得分:1)

您使用的系统未检测到您所使用的条形码类型。

但是,您可以使用不同的系统来检测更多种类的代码。查看AVCaptureMetadataOutput中使用的AVCaptureSession

有关其工作原理的摘要,请参阅https://ayeohyes.wordpress.com/2015/05/09/barcode-scanning-in-ios-using-avfoundation/