我有captured image
一段时间scanning QRCode
是这样的:
1)首先添加属性AVCaptureStillImageOutput's
@property (strong, nonatomic) AVCaptureStillImageOutput *stillImageOutput;
2)AVCaptureSession
初始化后添加会话预设
[self.session setSessionPreset:AVCaptureSessionPreset640x480];
3)现在添加AVCaptureStillImageOutput's
为输出AVCaptureSession
// 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
就是这样@Enjoy