ios 原生sdk 識別圖片中的二維碼

記憶有你發表於2016-01-28


UIImageView*tempImageView=(UIImageView*)gesture.view;

        if(tempImageView.image){

            //1. 初始化掃描器,設定設別型別和識別質量

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

            //2. 掃描獲取的特徵組

            NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:tempImageView.image.CGImage]];

            //3. 獲取掃描結果

            CIQRCodeFeature *feature = [features objectAtIndex:0];

            NSString *scannedResult = feature.messageString;

            UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"掃描結果" message:scannedResult delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];

            [alertView show];

        }else {

            

            UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"掃描結果" message:@"您還沒有生成二維碼" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];

            [alertView show];

        }

相關文章