我使用AVCaptureMetadataOutput是为了使用iOS QRCode,条形码扫描功能。这样做很好,我通过AVCaptureMetadataOutput委托方法获得了扫描结果。
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{但是我不知道如何用我在这个委托中的数据来捕获扫描的qrcode,条形码的图像。
发布于 2015-07-07 11:18:11
我有captured image,而scanning QRCode是这样的:
1)首先添加AVCaptureStillImageOutput's的属性
@property (strong, nonatomic) AVCaptureStillImageOutput *stillImageOutput;2)初始化后在AVCaptureSession中添加会话预置
[self.session setSessionPreset:AVCaptureSessionPreset640x480];3)现在在AVCaptureSession中添加AVCaptureStillImageOutput's作为输出
// Prepare an output for snapshotting
self.stillImageOutput = [AVCaptureStillImageOutput new];
[self.session addOutput:self.stillImageOutput];
self.stillImageOutput.outputSettings = @{AVVideoCodecKey: AVVideoCodecJPEG};4)在下面添加代码,以便在委托方法captureOutput:didOutputMetadataObjects:fromConnection:connection中捕获扫描图像
__block UIImage *scannedImg = nil;
// Take an image of the face and pass to CoreImage for detection
AVCaptureConnection *stillConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:stillConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if(error) {
NSLog(@"There was a problem");
return;
}
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
scannedImg = [UIImage imageWithData:jpegData];
NSLog(@"scannedImg : %@",scannedImg);
}];对于参考,使用CodeScanViewController
Thats it @
https://stackoverflow.com/questions/20782584
复制相似问题