1. 程式人生 > >識別圖片中的二維碼

識別圖片中的二維碼

csb 但是 ray hicsg nco graphics 截圖 get war

//截圖 再讀取

UIGraphicsBeginImageContextWithOptions(currentImageView.bounds.size, YES, 0);//currentImageView 圖片VIEW

CGContextRef context = UIGraphicsGetCurrentContext();

[self.layer renderInContext:context];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

//識別二維碼

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

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

CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:ciContext options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];// 二維碼識別

NSArray *features = [detector featuresInImage:ciImage];//手機連接Xcode運行到這就出問題 但是在手機上 運行沒問題

for (CIQRCodeFeature *feature in features) {

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

//對結果進行處理

}

識別圖片中的二維碼