I have captured image
while scanning QRCode
like this:
1) Firstly add property of AVCaptureStillImageOutput's
@property (strong, nonatomic) AVCaptureStillImageOutput *stillImageOutput;
2) Add session preset in AVCaptureSession
after initializing it
[self.session setSessionPreset:AVCaptureSessionPreset640x480];
3) Now add AVCaptureStillImageOutput's
as output in AVCaptureSession
// Prepare an output for snapshotting
self.stillImageOutput = [AVCaptureStillImageOutput new];
[self.session addOutput:self.stillImageOutput];
self.stillImageOutput.outputSettings = @{AVVideoCodecKey: AVVideoCodecJPEG};
4) Make add below code to capture scanned image in delegate method 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);
}];
For reference use CodeScanViewController
Thats it @Enjoy