识别图片中的二维码

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33608748/article/details/81301053

- (void)qrScan:(UIImage *)image{

    CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];

    CIContext *context = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}]; // 渲染

    CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];// 识别

    // 注意这里的CIDetectorTypeQRCode

    NSArray *features = [detector featuresInImage:ciImage];

    NSLog(@"features = %@",features); // 识别后的结果

    for (CIQRCodeFeature *feature in features) {

        NSLog(@"msg = %@",feature.messageString); // 打印二维码中的信息

 //根据自己的需求对str做处理

        NSString *str = [NSString stringWithFormat:@"%@",feature.messageString];

        if ([str hasPrefix:@"http://"]||[str hasPrefix:@"https://"]) {//调到safari浏览器

            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

        }    }

}

展开阅读全文

没有更多推荐了,返回首页